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 Laurent Perez <ha...@gmail.com> on 2008/07/23 21:40:14 UTC

Expected null behaviour of cookie.getDomain()/cookie.getPath() ?

Hi

I'm using commons httpclient to perform a server side request, triggered by
a client (a real browser).
Once the server side request is done, I'm copying the server client cookies
to the client one using response.addCookie(servercookie) : this works as
expected, my client browser receives the cookies.

However, when this client browser performs another request (same page, same
domain), when I display its cookies from its HttpServletRequest (so the
Cookie is not a commons httpclient one, it's a javax.servlet.http.Cookie),
then cookie.getDomain() and cookie.getPath() are always null ; but
cookie.getName() and cookie.getValue() are ok.

I understand why domain and path could be "treated as null", because if I
receive the cookies name and value, then it means they were transmited for
the correct domain and path, but this still puzzles me : why is
javax.servlet.http.Cookies exposing getters for domain and path if the
returned value is always a null ? Tested on jetty and tomcat.

Hope someone can enlighten me :)

thanks !
laurent


-- 
<a href="http://in-pocket.blogspot.com">http://in-pocket.blogspot.com -
Mobile world, technology and more</a>

Re: Expected null behaviour of cookie.getDomain()/cookie.getPath() ?

Posted by Oleg Kalnichevski <ol...@apache.org>.
Laurent Perez wrote:
> Hi
>
> I'm using commons httpclient to perform a server side request, triggered by
> a client (a real browser).
> Once the server side request is done, I'm copying the server client cookies
> to the client one using response.addCookie(servercookie) : this works as
> expected, my client browser receives the cookies.
>
> However, when this client browser performs another request (same page, same
> domain), when I display its cookies from its HttpServletRequest (so the
> Cookie is not a commons httpclient one, it's a javax.servlet.http.Cookie),
> then cookie.getDomain() and cookie.getPath() are always null ; but
> cookie.getName() and cookie.getValue() are ok.
>
> I understand why domain and path could be "treated as null", because if I
> receive the cookies name and value, then it means they were transmited for
> the correct domain and path, but this still puzzles me : why is
> javax.servlet.http.Cookies exposing getters for domain and path if the
> returned value is always a null ? Tested on jetty and tomcat.
>
> Hope someone can enlighten me :)
>
> thanks !
> laurent
>
>   

Laurent,

A cookie's path and domain attributes are set to null if they have not 
been explicitly set by the origin server (which is often the case). In 
this case your application should be using the effective domain / path 
values. See the HTTP state management spec for details.

Oleg




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