You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Philippe Mouawad <pm...@apache.org> on 2015/12/15 21:40:04 UTC

Domain value returns by getDomain()

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());
        }
    }
}

Re: Domain value returns by getDomain()

Posted by Philippe Mouawad <ph...@gmail.com>.
So If we want to know if Domain cookie was set, can we test with this:
((BasicClientCookie)cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)

As we need a way to distinguish a cookie with ".bt.com" vs "bt.com" so that
if next request is for a subdomain we send the cookie.
Thanks

On Wed, Dec 16, 2015 at 9:38 PM, Philippe Mouawad <
philippe.mouawad@gmail.com> wrote:

> Thanks !
>
> On Wed, Dec 16, 2015 at 9:34 PM, Oleg Kalnichevski <ol...@apache.org>
> wrote:
>
>> On Tue, 2015-12-15 at 21:40 +0100, Philippe Mouawad wrote:
>> > 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 ?
>> >
>>
>> Please see
>>
>> http://tools.ietf.org/html/rfc6265#section-5.2.3
>>
>> Oleg
>>
>>
>
>
> --
> Cordialement.
> Philippe Mouawad.
>
>
>


-- 
Cordialement.
Philippe Mouawad.

Re: Domain value returns by getDomain()

Posted by Philippe Mouawad <ph...@gmail.com>.
So If we want to know if Domain cookie was set, can we test with this:
((BasicClientCookie)cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)

As we need a way to distinguish a cookie with ".bt.com" vs "bt.com" so that
if next request is for a subdomain we send the cookie.
Thanks

On Wed, Dec 16, 2015 at 9:38 PM, Philippe Mouawad <
philippe.mouawad@gmail.com> wrote:

> Thanks !
>
> On Wed, Dec 16, 2015 at 9:34 PM, Oleg Kalnichevski <ol...@apache.org>
> wrote:
>
>> On Tue, 2015-12-15 at 21:40 +0100, Philippe Mouawad wrote:
>> > 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 ?
>> >
>>
>> Please see
>>
>> http://tools.ietf.org/html/rfc6265#section-5.2.3
>>
>> Oleg
>>
>>
>
>
> --
> Cordialement.
> Philippe Mouawad.
>
>
>


-- 
Cordialement.
Philippe Mouawad.

Re: Domain value returns by getDomain()

Posted by Philippe Mouawad <ph...@gmail.com>.
Thanks !

On Wed, Dec 16, 2015 at 9:34 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Tue, 2015-12-15 at 21:40 +0100, Philippe Mouawad wrote:
> > 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 ?
> >
>
> Please see
>
> http://tools.ietf.org/html/rfc6265#section-5.2.3
>
> Oleg
>
>


-- 
Cordialement.
Philippe Mouawad.

Re: Domain value returns by getDomain()

Posted by Philippe Mouawad <ph...@gmail.com>.
Thanks !

On Wed, Dec 16, 2015 at 9:34 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Tue, 2015-12-15 at 21:40 +0100, Philippe Mouawad wrote:
> > 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 ?
> >
>
> Please see
>
> http://tools.ietf.org/html/rfc6265#section-5.2.3
>
> Oleg
>
>


-- 
Cordialement.
Philippe Mouawad.

Re: Domain value returns by getDomain()

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2015-12-15 at 21:40 +0100, Philippe Mouawad wrote:
> 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 ?
> 

Please see

http://tools.ietf.org/html/rfc6265#section-5.2.3

Oleg


Re: Domain value returns by getDomain()

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2015-12-15 at 21:40 +0100, Philippe Mouawad wrote:
> 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 ?
> 

Please see

http://tools.ietf.org/html/rfc6265#section-5.2.3

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org