Re: Fetch API Sends Lower Case Headers

108 views
Skip to first unread message

PhistucK

unread,
Jun 26, 2016, 9:37:29 AM6/26/16
to blink-dev, net-dev, Matt Menke
Does Blink intentionally convert header names to lower case when using the fetch API?
And if so, does that conform to the specification (Firefox only converts some)?
See below for details...


PhistucK

On Sun, Jun 26, 2016 at 2:15 PM, Matt Menke <mme...@chromium.org> wrote:
The network stack sends the headers with the case it gets (Except for H2/QUIC, where headers are specced to be lower case).  Code you're looking for that does this is more likely in blink.

On Sun, Jun 26, 2016 at 2:50 AM, PhistucK <phis...@gmail.com> wrote:
I tried this -
fetch("/foo?bar=6", {method: 'get', headers: {'X-Requested-With': 'XMLHttpRequest', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Authorization': 'd'}});

Chrome converts all of the header names I specified to lower case. Firefox only converts X-Requested-With to lower case.

While I know that headers should be case insensitive, I wonder why Chrome does that and Firefox does something else. This looks like an interoperation issue (a small one, but still).

Who is right?


PhistucK

--
You received this message because you are subscribed to the Google Groups "net-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to net-dev+u...@chromium.org.
To post to this group, send email to net...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/net-dev/CABc02_JuMBBzGad4Wp6z4SpVQHixz3cxBQ9a9L2HQF%2BajKprLA%40mail.gmail.com.


Taiju Tsuiki

unread,
Jun 26, 2016, 9:50:01 AM6/26/16
to PhistucK, blink-dev, net-dev, Matt Menke
According to the fetch spec, all operation to the header uses byte-lowercased header name.
Here is a recent spec discussion about it on a github issue: Optional disable setting headers keys in lowercase

PhistucK

unread,
Jun 26, 2016, 10:05:28 AM6/26/16
to Taiju Tsuiki, blink-dev, net-dev, Matt Menke
Thank you!


PhistucK

Ben Kelly

unread,
Jun 27, 2016, 9:47:29 AM6/27/16
to PhistucK, blink-dev, net-dev, Matt Menke
On Sun, Jun 26, 2016 at 9:36 AM, PhistucK <phis...@gmail.com> wrote:
Does Blink intentionally convert header names to lower case when using the fetch API?
And if so, does that conform to the specification (Firefox only converts some)?

Hmm, for Firefox we lower case headers when added via js to the Headers object.  We don't, however, lower case headers for any other place in the tree that adds headers.  So our network stack does not use the Headers object, so does not get the lower casing.

I filed a bug for this, but I'm not sure if we will implement it:

https://bugzilla.mozilla.org/show_bug.cgi?id=1282426

Hope that helps.

Ben

PhistucK

unread,
Jun 27, 2016, 9:57:26 AM6/27/16
to Ben Kelly, blink-dev, net-dev
When I try it on www.walla.co.il, the previously mentioned code produces this (taken from "Raw headers" in the Firefox Developer Tools) -
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
x-requested-with: XMLHttpRequest
Authorization: d
Connection: keep-alive

So, like I wrote, only some (x-requested-with) are converted, even though all of them were added in the same way.​


PhistucK

Ben Kelly

unread,
Jun 27, 2016, 10:09:23 AM6/27/16
to PhistucK, blink-dev, net-dev
Yea, it appears we actually normalize to the mixed-case when we atomize standard headers.  I'll add this to the spec discussion.

Thanks for pointing it out!

Ben

PhistucK

unread,
Jun 27, 2016, 10:12:55 AM6/27/16
to Ben Kelly, blink-dev, net-dev
WebKit does that, too.


PhistucK
Reply all
Reply to author
Forward
0 new messages