You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Christopher Brind <br...@brindy.org.uk> on 2009/05/22 13:43:39 UTC

Query handling multiple response headers with same name

Hi,

Off the back of Sandro's email earlier I was looking at the Query class and
notice that it uses a dictionary to store the response headers:

int i = 1;
> for (String key = connection.getHeaderFieldKey(i);
> key != null;
> key = connection.getHeaderFieldKey(++i)) {
> responseProperties.put(key, connection.getHeaderField(i));
> }
>

However, you can have multiple headers with the same name, e.g.

Set-Cookie: name=MyCookie; value=Some value
Set-Cookie: name=AnotherCookie; value=666
MyHeader: hello
MyHeader: world

The code above would overwrite proceeding values with the most recent one
retrieved so the result of the above would be a map with the following:

Set-Cookie: name=AnotherCookie; value=666
MyHeader: world

The obvious solution is to change

public final class RequestPropertiesDictionary
        implements Dictionary<String, String>, Iterable<String>


To

public final class RequestPropertiesDictionary
        implements Dictionary<String, String[]>, Iterable<String>


and fix the Query class to cope with an array, e.g.

for (String key = connection.getHeaderFieldKey(i);
                key != null;
                key = connection.getHeaderFieldKey(++i)) {

     String[] values = responseProperties.get(key);
     if (null == values) {
        values = new String[1];
     } else {

     }
     values[values.length - 1] = connection.getHeaderField(i)
                responseProperties.put(key, );

}



Any thoughts?

If this is valid I'll create a JIRA issue and submit a fix (it's been a
while since I've committed anything!) and fix up anything dependent on the
existing version of RequestPropertiesDictionary.

Cheers,
Chris

Re: Query handling multiple response headers with same name

Posted by Sandro Martini <sa...@gmail.com>.
Hi Christopher,
I'll wait your modifications (if accepted by others, for me they are
ok), to adapt my code (if accepted too).

Thanks and bye,
Sandro

Re: Query handling multiple response headers with same name

Posted by Christopher Brind <br...@brindy.org.uk>.
Sorry, hit send too soon in the fix example below, but you get the idea.

Cheers,
Chris


2009/5/22 Christopher Brind <br...@brindy.org.uk>

> Hi,
>
> Off the back of Sandro's email earlier I was looking at the Query class and
> notice that it uses a dictionary to store the response headers:
>
> int i = 1;
>> for (String key = connection.getHeaderFieldKey(i);
>> key != null;
>> key = connection.getHeaderFieldKey(++i)) {
>>  responseProperties.put(key, connection.getHeaderField(i));
>> }
>>
>
> However, you can have multiple headers with the same name, e.g.
>
> Set-Cookie: name=MyCookie; value=Some value
> Set-Cookie: name=AnotherCookie; value=666
> MyHeader: hello
> MyHeader: world
>
> The code above would overwrite proceeding values with the most recent one
> retrieved so the result of the above would be a map with the following:
>
> Set-Cookie: name=AnotherCookie; value=666
> MyHeader: world
>
> The obvious solution is to change
>
> public final class RequestPropertiesDictionary
>         implements Dictionary<String, String>, Iterable<String>
>
>
> To
>
> public final class RequestPropertiesDictionary
>
>         implements Dictionary<String, String[]>, Iterable<String>
>
>
> and fix the Query class to cope with an array, e.g.
>
> for (String key = connection.getHeaderFieldKey(i);
>                 key != null;
>
>                 key = connection.getHeaderFieldKey(++i)) {
>
>      String[] values = responseProperties.get(key);
>      if (null == values) {
>         values = new String[1];
>      } else {
>
>      }
>      values[values.length - 1] = connection.getHeaderField(i)
>
>                 responseProperties.put(key, );
>
> }
>
>
>
> Any thoughts?
>
> If this is valid I'll create a JIRA issue and submit a fix (it's been a
> while since I've committed anything!) and fix up anything dependent on the
> existing version of RequestPropertiesDictionary.
>
> Cheers,
> Chris
>
>
>