Bug 117342 - [curl] Merge http response header values
Summary: [curl] Merge http response header values
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: Curl
Depends on:
Blocks: 117300
  Show dependency treegraph
 
Reported: 2013-06-07 05:44 PDT by Peter Gal
Modified: 2013-06-13 21:47 PDT (History)
2 users (show)

See Also:


Attachments
proposed patch (1.53 KB, patch)
2013-06-07 05:51 PDT, Peter Gal
kenneth: review+
Details | Formatted Diff | Diff
advanced patch (3.02 KB, patch)
2013-06-13 06:14 PDT, Peter Gal
no flags Details | Formatted Diff | Diff
style fixed patch (3.02 KB, patch)
2013-06-13 06:47 PDT, Peter Gal
bfulgham: review-
Details | Formatted Diff | Diff
updated patch (3.02 KB, patch)
2013-06-13 09:56 PDT, Peter Gal
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Gal 2013-06-07 05:44:05 PDT
If the server returns multiple headers with the same name then the values should be merged into one list where the values are separated by a ',' character. This behavior is described in the RFC 2616 section 4.2 (http://tools.ietf.org/html/rfc2616#section-4.2).
Comment 1 Peter Gal 2013-06-07 05:45:39 PDT
For example if the server returns the following headers:

X-MY: one
X-MY: two

then the client should merge these values into a single:

X-MY: one, two

entry.

This is tested with the 'http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers.html' testcase.
Comment 2 Peter Gal 2013-06-07 05:51:38 PDT
Created attachment 204033 [details]
proposed patch

The current implement used the setHTTPHeaderField method which replaced the previous header. There the addHTTPHeaderField method which will concatenate the values if required.
Comment 3 Kenneth Rohde Christiansen 2013-06-08 04:17:23 PDT
Comment on attachment 204033 [details]
proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=204033&action=review

> Source/WebCore/ChangeLog:9
> +        No new tests, already covered by existing ones, for example:
> +        http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers.html

why no updated results?
Comment 4 Peter Gal 2013-06-08 04:33:43 PDT
(In reply to comment #3)
> (From update of attachment 204033 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=204033&action=review
> 
> > Source/WebCore/ChangeLog:9
> > +        No new tests, already covered by existing ones, for example:
> > +        http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers.html
> 
> why no updated results?

The test results are ok, it's just that the test was failing before.
Comment 5 Brent Fulgham 2013-06-08 14:17:18 PDT
Comment on attachment 204033 [details]
proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=204033&action=review

> Source/WebCore/platform/network/curl/ResourceHandleManager.cpp:320
> +            d->m_response.addHTTPHeaderField(header.left(splitPos), header.substring(splitPos+1).stripWhiteSpace());

Are there ever cases where we do want to replace the HTTP header field, rather than appending?
Comment 6 Peter Gal 2013-06-10 00:38:33 PDT
(In reply to comment #5)
> (From update of attachment 204033 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=204033&action=review
> 
> > Source/WebCore/platform/network/curl/ResourceHandleManager.cpp:320
> > +            d->m_response.addHTTPHeaderField(header.left(splitPos), header.substring(splitPos+1).stripWhiteSpace());
> 
> Are there ever cases where we do want to replace the HTTP header field, rather than appending?

I was wondering on that also, so I've re-read the rfc multiple times and as far as I can see most of the headers are allowed to be merged. If I remember correctly libsoup merges all HTTP headers. In the blackberry they have a white list to specify which headers can be merged.

Should I do something like the blackberry guys and add a white list?
Comment 7 Peter Gal 2013-06-13 06:14:12 PDT
Created attachment 204578 [details]
advanced patch

So then... After studying the HTTP RFC and other things I've created a slightly more advanced implementation to merge HTTP header values.
Comment 8 WebKit Commit Bot 2013-06-13 06:16:04 PDT
Attachment 204578 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/ChangeLog', u'Source/WebCore/platform/network/curl/ResourceHandleManager.cpp']" exit_code: 1
Source/WebCore/platform/network/curl/ResourceHandleManager.cpp:274:  Omit int when using unsigned  [runtime/unsigned] [1]
Total errors found: 1 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Peter Gal 2013-06-13 06:47:17 PDT
Created attachment 204580 [details]
style fixed patch

fixed the style error
Comment 10 Brent Fulgham 2013-06-13 09:41:17 PDT
Comment on attachment 204580 [details]
style fixed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=204580&action=review

Looks great!  I had a couple of minor suggestions.  If you can clarify that comment I will be happy to approve the patch.

> Source/WebCore/platform/network/curl/ResourceHandleManager.cpp:241
> +    static const char *appendableHeaders[] = {

This should be "static const char*"  The fact that this is a "const char pointer" is part of the type.

> Source/WebCore/platform/network/curl/ResourceHandleManager.cpp:270
> +    // Custom headers usually starts with 'X-', allow them.

"starts" should be "start" (syntax).

If they usually start with "X-", why do we test with "x-" (case insensitive)?  Do they usually start with either "X-" or "x-" and we are handling this case and exiting early?

Maybe the comments should be "Custom headers start with 'X-', and need no further checking.
Comment 11 Peter Gal 2013-06-13 09:47:40 PDT
(In reply to comment #10)
> (From update of attachment 204580 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=204580&action=review
> 
> Looks great!  I had a couple of minor suggestions.  If you can clarify that comment I will be happy to approve the patch.
> 
> > Source/WebCore/platform/network/curl/ResourceHandleManager.cpp:241
> > +    static const char *appendableHeaders[] = {
> 
> This should be "static const char*"  The fact that this is a "const char pointer" is part of the type.
> 

Ok.

> > Source/WebCore/platform/network/curl/ResourceHandleManager.cpp:270
> > +    // Custom headers usually starts with 'X-', allow them.
> 
> "starts" should be "start" (syntax).
> 
> If they usually start with "X-", why do we test with "x-" (case insensitive)?  Do they usually start with either "X-" or "x-" and we are handling this case and exiting early?
> 
> Maybe the comments should be "Custom headers start with 'X-', and need no further checking.

The http headers are case insensitive (at least that's what I read in the rfc) and most of the times the first character is in uppercase. I'll update the comment.
.
Comment 12 Peter Gal 2013-06-13 09:56:14 PDT
Created attachment 204625 [details]
updated patch
Comment 13 Brent Fulgham 2013-06-13 21:24:47 PDT
Comment on attachment 204625 [details]
updated patch

r=me.  Thanks for working on this!
Comment 14 WebKit Commit Bot 2013-06-13 21:47:27 PDT
Comment on attachment 204625 [details]
updated patch

Clearing flags on attachment: 204625

Committed r151580: <http://trac.webkit.org/changeset/151580>
Comment 15 WebKit Commit Bot 2013-06-13 21:47:30 PDT
All reviewed patches have been landed.  Closing bug.