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 pv...@xs4all.nl on 2012/11/07 19:43:17 UTC

RE: httpcore parses expires in Set-Cookie wrong

Hi JM,

Look again: the ',' in

           "expires=Sun, 03-Nov-2013 10:54:41 GMT;"

is parsed as if it were a ';' .

That leads to
  expires=Sun
and
  03-Nov-2013 10:54:41 GMT=null

I can't believe I'm the first person to notice this...

Paul.


>
>Hi Paul,
>
>I don't see anything wrong with the output. What will have you expected?
>
>JM
>
>2012/11/6, pvbemmel@xs4all.nl <pv...@xs4all.nl>:
>>
>> I'm using httpcore-4.2.1 , and code below shows the problem.
>> The code is similar to that on page 2 of the httpcore tutorial pdf.
>> I only added a Set-Cookie with an expires header element .
>> -------------------------------------------------------------------
>>
>> import org.apache.http.*;
>> import org.apache.http.message.*;
>>
>> public class Page2 {
>>
>>   public static void main(String[] args) {
>>     HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
>>         HttpStatus.SC_OK, "OK");
>>     response.addHeader("Set-Cookie", "c1=a; path=/; domain=localhost");
>>     response.addHeader("Set-Cookie",
>>         "c2=b; path=\"/\", c3=c; domain=\"localhost\"");
>>     response.addHeader("Set-Cookie",
>>         "c2=b; expires=Sun, 03-Nov-2013 10:54:41 GMT;" +
>>         " path=\"/\", c3=c; domain=\"localhost\"");
>>     HeaderElementIterator it = new BasicHeaderElementIterator(
>>         response.headerIterator("Set-Cookie"));
>>     while (it.hasNext()) {
>>       HeaderElement elem = it.nextElement();
>>       System.out.println(elem.getName() + " = " + elem.getValue());
>>       NameValuePair[] params = elem.getParameters();
>>       for (int i = 0; i < params.length; i++) {
>>         System.out.println(" " + params[i]);
>>       }
>>     }
>>   }
>> }
>> -------------------------------------------------------------------
>> It produces output
>>
>> c1 = a
>>  path=/
>>  domain=localhost
>> c2 = b
>>  path=/
>> c3 = c
>>  domain=localhost
>> c2 = b
>>  expires=Sun
>> 03-Nov-2013 10:54:41 GMT = null
>>  path=/
>> c3 = c
>>  domain=localhost
>>
>> Clearly the date is parsed wrong.
>>
>> Is this a bug in httpcore, or am i doing something wrong?
>>
>> Regards,
>> Paul van Bemmelen
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
>
>>



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


Re: httpcore parses expires in Set-Cookie wrong

Posted by Jean-Marc Spaggiari <je...@spaggiari.org>.
Oh! I see!

This is working fine:

response.addHeader("Set-Cookie", "c2=b; expires=\"Sun, 03-Nov-2013
10:54:41 GMT\"; path=\"/\", c3=c; domain=\"localhost\"");

2012/11/7, pvbemmel@xs4all.nl <pv...@xs4all.nl>:
>
> Hi JM,
>
> Look again: the ',' in
>
>            "expires=Sun, 03-Nov-2013 10:54:41 GMT;"
>
> is parsed as if it were a ';' .
>
> That leads to
>   expires=Sun
> and
>   03-Nov-2013 10:54:41 GMT=null
>
> I can't believe I'm the first person to notice this...
>
> Paul.
>
>
>>
>>Hi Paul,
>>
>>I don't see anything wrong with the output. What will have you expected?
>>
>>JM
>>
>>2012/11/6, pvbemmel@xs4all.nl <pv...@xs4all.nl>:
>>>
>>> I'm using httpcore-4.2.1 , and code below shows the problem.
>>> The code is similar to that on page 2 of the httpcore tutorial pdf.
>>> I only added a Set-Cookie with an expires header element .
>>> -------------------------------------------------------------------
>>>
>>> import org.apache.http.*;
>>> import org.apache.http.message.*;
>>>
>>> public class Page2 {
>>>
>>>   public static void main(String[] args) {
>>>     HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
>>>         HttpStatus.SC_OK, "OK");
>>>     response.addHeader("Set-Cookie", "c1=a; path=/; domain=localhost");
>>>     response.addHeader("Set-Cookie",
>>>         "c2=b; path=\"/\", c3=c; domain=\"localhost\"");
>>>     response.addHeader("Set-Cookie",
>>>         "c2=b; expires=Sun, 03-Nov-2013 10:54:41 GMT;" +
>>>         " path=\"/\", c3=c; domain=\"localhost\"");
>>>     HeaderElementIterator it = new BasicHeaderElementIterator(
>>>         response.headerIterator("Set-Cookie"));
>>>     while (it.hasNext()) {
>>>       HeaderElement elem = it.nextElement();
>>>       System.out.println(elem.getName() + " = " + elem.getValue());
>>>       NameValuePair[] params = elem.getParameters();
>>>       for (int i = 0; i < params.length; i++) {
>>>         System.out.println(" " + params[i]);
>>>       }
>>>     }
>>>   }
>>> }
>>> -------------------------------------------------------------------
>>> It produces output
>>>
>>> c1 = a
>>>  path=/
>>>  domain=localhost
>>> c2 = b
>>>  path=/
>>> c3 = c
>>>  domain=localhost
>>> c2 = b
>>>  expires=Sun
>>> 03-Nov-2013 10:54:41 GMT = null
>>>  path=/
>>> c3 = c
>>>  domain=localhost
>>>
>>> Clearly the date is parsed wrong.
>>>
>>> Is this a bug in httpcore, or am i doing something wrong?
>>>
>>> Regards,
>>> Paul van Bemmelen
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>
>>>
>>
>>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

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


Re: httpcore parses expires in Set-Cookie wrong

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2012-11-07 at 19:43 +0100, pvbemmel@xs4all.nl wrote:
> Hi JM,
> 
> Look again: the ',' in
> 
>            "expires=Sun, 03-Nov-2013 10:54:41 GMT;"
> 
> is parsed as if it were a ';' .
> 
> That leads to
>   expires=Sun
> and
>   03-Nov-2013 10:54:41 GMT=null
> 
> I can't believe I'm the first person to notice this...
> 
> Paul.
> 
> 

The header in question is not a valid cookie as defined by the HTTP
specification. It contains a reserved character (comma) without
enclosing quote marks in one of the attribute values.

Oleg

> >
> >Hi Paul,
> >
> >I don't see anything wrong with the output. What will have you expected?
> >
> >JM
> >
> >2012/11/6, pvbemmel@xs4all.nl <pv...@xs4all.nl>:
> >>
> >> I'm using httpcore-4.2.1 , and code below shows the problem.
> >> The code is similar to that on page 2 of the httpcore tutorial pdf.
> >> I only added a Set-Cookie with an expires header element .
> >> -------------------------------------------------------------------
> >>
> >> import org.apache.http.*;
> >> import org.apache.http.message.*;
> >>
> >> public class Page2 {
> >>
> >>   public static void main(String[] args) {
> >>     HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
> >>         HttpStatus.SC_OK, "OK");
> >>     response.addHeader("Set-Cookie", "c1=a; path=/; domain=localhost");
> >>     response.addHeader("Set-Cookie",
> >>         "c2=b; path=\"/\", c3=c; domain=\"localhost\"");
> >>     response.addHeader("Set-Cookie",
> >>         "c2=b; expires=Sun, 03-Nov-2013 10:54:41 GMT;" +
> >>         " path=\"/\", c3=c; domain=\"localhost\"");
> >>     HeaderElementIterator it = new BasicHeaderElementIterator(
> >>         response.headerIterator("Set-Cookie"));
> >>     while (it.hasNext()) {
> >>       HeaderElement elem = it.nextElement();
> >>       System.out.println(elem.getName() + " = " + elem.getValue());
> >>       NameValuePair[] params = elem.getParameters();
> >>       for (int i = 0; i < params.length; i++) {
> >>         System.out.println(" " + params[i]);
> >>       }
> >>     }
> >>   }
> >> }
> >> -------------------------------------------------------------------
> >> It produces output
> >>
> >> c1 = a
> >>  path=/
> >>  domain=localhost
> >> c2 = b
> >>  path=/
> >> c3 = c
> >>  domain=localhost
> >> c2 = b
> >>  expires=Sun
> >> 03-Nov-2013 10:54:41 GMT = null
> >>  path=/
> >> c3 = c
> >>  domain=localhost
> >>
> >> Clearly the date is parsed wrong.
> >>
> >> Is this a bug in httpcore, or am i doing something wrong?
> >>
> >> Regards,
> >> Paul van Bemmelen
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >>
> >>
> >
> >>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 



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