Hello,
I would like to know if it's a bug or regular.
In the below Test case, we have a cookie which domain attribute is "domain=.
bt.com"
But the built cookie by HttpClient return "bt.com" , it's explicitely in
the code of BasicDomainHandler#domainMatch.
I suppose it's voluntary right ?
Thanks in advance.
package org.apache.http.client.protocol;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.HttpVersion;
import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.SM;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.DefaultCookieSpec;
import org.apache.http.message.BasicHttpResponse;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class TestCookieDomain {
private CookieOrigin cookieOrigin;
private CookieSpec cookieSpec;
private CookieStore cookieStore;
@Before
public void setUp() throws Exception {
this.cookieOrigin = new CookieOrigin("subdomain.bt.com", 80,
"/path", false);
this.cookieSpec = new DefaultCookieSpec();
this.cookieStore = new BasicCookieStore();
}
@Test
public void testDomainWithDot() throws Exception {
final HttpResponse response = new BasicHttpResponse(
HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE, "SMTRYNO=1; path=/; domain=.bt.com
");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN,
this.cookieOrigin);
context.setAttribute(HttpClientContext.COOKIE_SPEC,
this.cookieSpec);
context.setAttribute(HttpClientContext.COOKIE_STORE,
this.cookieStore);
final HttpResponseInterceptor interceptor = new
ResponseProcessCookies();
interceptor.process(response, context);
final List<Cookie> clientCookies = this.cookieStore.getCookies();
Assert.assertEquals(1, clientCookies.size());
for (Cookie cookie : clientCookies) {
Assert.assertEquals(".bt.com", cookie.getDomain());
}
}
}