Header parsing bug in SimpleCall

8 messages Options
Embed this post
Permalink
Arjohn Kampman

Header parsing bug in SimpleCall

Reply Threaded More More options
Print post
Permalink
Hi all,

First of all, I hope I'm sending this to the right mailing list. Please
let me know if there's a better place.

I think I have run into a bug in SimpleCall.getRequestHeaders()
(package org.restlet.ext.simple.internal). This method takes the first
header value and ignores the rest. My client includes multiple Accept
header in the request, but the restlet engine only sees the first.

The bug is in this code:

    for (String name : names) {
       result.add(new Parameter(name, this.request.getValue(name)));
    }

This iterates over all header names, but just selects the first value
for each name. This should probably look something like this:

    for (String name : names) {
       for (String value : this.request.getValues(name)) {
          result.add(new Parameter(name, value));
       }
    }

Please investigate and fix :-)


--
Arjohn Kampman, Senior Software Engineer
Aduna - Semantic Power
www.aduna-software.com

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2414381
Thierry Boileau

Re: Header parsing bug in SimpleCall

Reply Threaded More More options
Print post
Permalink
Hello Arjohn

may I ask you what kind of client are you using?
I'm not aware the HTTP RFC allows to send several accept headers in the
same request, since it allows to specify a list of preferences inside a
single header.

Does anybody else has a thought about this point?

Best regards,
Thierry Boileau

> Hi all,
>
> First of all, I hope I'm sending this to the right mailing list. Please
> let me know if there's a better place.
>
> I think I have run into a bug in SimpleCall.getRequestHeaders()
> (package org.restlet.ext.simple.internal). This method takes the first
> header value and ignores the rest. My client includes multiple Accept
> header in the request, but the restlet engine only sees the first.
>
> The bug is in this code:
>
>     for (String name : names) {
>        result.add(new Parameter(name, this.request.getValue(name)));
>     }
>
> This iterates over all header names, but just selects the first value
> for each name. This should probably look something like this:
>
>     for (String name : names) {
>        for (String value : this.request.getValues(name)) {
>           result.add(new Parameter(name, value));
>        }
>     }
>
> Please investigate and fix :-)
>
>
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2414703
Arjohn Kampman

Re: Header parsing bug in SimpleCall

Reply Threaded More More options
Print post
Permalink
Thierry Boileau wrote:
> Hello Arjohn
>
> may I ask you what kind of client are you using?
> I'm not aware the HTTP RFC allows to send several accept headers in the
> same request, since it allows to specify a list of preferences inside a
> single header.

I'm using Apache's HttpClient 3.1. I'm creating the request by calling
method.addRequestHeader("Accept", acceptParam) multiple times.

--
Arjohn

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2414705
Arjohn Kampman

Re: Header parsing bug in SimpleCall

Reply Threaded More More options
Print post
Permalink
Arjohn Kampman wrote:

> Thierry Boileau wrote:
>> Hello Arjohn
>>
>> may I ask you what kind of client are you using?
>> I'm not aware the HTTP RFC allows to send several accept headers in
>> the same request, since it allows to specify a list of preferences
>> inside a single header.
>
> I'm using Apache's HttpClient 3.1. I'm creating the request by calling
> method.addRequestHeader("Accept", acceptParam) multiple times.

It looks like RFC 2616 allows it. From section 4.2:

    Multiple message-header fields with the same field-name MAY be
    present in a message if and only if the entire field-value for that
    header field is defined as a comma-separated list


--
Arjohn Kampman, Senior Software Engineer
Aduna - Semantic Power
www.aduna-software.com

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2414706
Thierry Boileau

Re: Header parsing bug in SimpleCall

Reply Threaded More More options
Print post
Permalink
Hi,

thanks Arjohn, I forgot that point.
And as I notice that the other server connectors behave properly it
clearly shows that this is a bug. Thanks a lot Arjohn.
The fix is available in the svn repository.

Best regards,
Thierry Boileau

>>> Hello Arjohn
>>>
>>> may I ask you what kind of client are you using?
>>> I'm not aware the HTTP RFC allows to send several accept headers in
>>> the same request, since it allows to specify a list of preferences
>>> inside a single header.
>>>      
>> I'm using Apache's HttpClient 3.1. I'm creating the request by calling
>> method.addRequestHeader("Accept", acceptParam) multiple times.
>>    
>
> It looks like RFC 2616 allows it. From section 4.2:
>
>     Multiple message-header fields with the same field-name MAY be
>     present in a message if and only if the entire field-value for that
>     header field is defined as a comma-separated list
>
>
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2414710
Arjohn Kampman

Re: Header parsing bug in SimpleCall

Reply Threaded More More options
Print post
Permalink
Thierry Boileau wrote:
> Hi,
>
> thanks Arjohn, I forgot that point.
> And as I notice that the other server connectors behave properly it
> clearly shows that this is a bug. Thanks a lot Arjohn.
> The fix is available in the svn repository.


Thank you for fixing it. Will I also use the maven snapshot to test the
bugfix? The current snapshot seems to be a few days old. What's the
strategy wrt building snapshots for restlet?

Arjohn

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2414887
Thierry Boileau

Re: Header parsing bug in SimpleCall

Reply Threaded More More options
Print post
Permalink
Hello Arjohn,

there are 2 maven repository one is private and is updated every day,
the other one is public and is updated only on 1st and 15th of each
month (http://www.restlet.org/downloads/maven).
Otherwise, daily snapshots are available from this page
http://www.restlet.org/downloads/unstable.

best regards,
Thierry Boileau

>> Hi,
>>
>> thanks Arjohn, I forgot that point.
>> And as I notice that the other server connectors behave properly it
>> clearly shows that this is a bug. Thanks a lot Arjohn.
>> The fix is available in the svn repository.
>>    
>
>
> Thank you for fixing it. Will I also use the maven snapshot to test the
> bugfix? The current snapshot seems to be a few days old. What's the
> strategy wrt building snapshots for restlet?
>
> Arjohn
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2414887
>
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2415014
Arjohn Kampman

Re: Header parsing bug in SimpleCall

Reply Threaded More More options
Print post
Permalink
Hi Thierry,

I can confirm that this issue has also been fixed in the most recent
snapshot builds from the public maven repo.

Arjohn


Thierry Boileau wrote:
> Hello Arjohn,
>
> there are 2 maven repository one is private and is updated every day,
> the other one is public and is updated only on 1st and 15th of each
> month (http://www.restlet.org/downloads/maven).
> Otherwise, daily snapshots are available from this page
> http://www.restlet.org/downloads/unstable.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2420008