-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why are headers a special data-structure? #154
Comments
Because they have all kinds of restrictions and actually allow duplicate keys. You should be able to use an object as input though in most cases. Was this unclear from reading the standard? Would a note somewhere help? If so, where? |
The only mention of duplicate headers I found in 5.6 CORS-preflight fetch. It might be nice to say that duplicates are allowed somewhere. So it wasn't clear to me that duplicates are possible. I had a feeling that what I'm asking is an 'out-of-place' question since I'm still quite new to reading specs. I guess what I'd really like to know more about is the thought process that lead up to the way thing sare, because without it I keep finding myself asking: Why was this designed in that way. Does that make sense? Should I just look at the git history, or are there other better places to understand why the spec is like it is? |
I'm happy with folks opening issues if something is unclear. That you can have multiple headers follows from HTTP and the definitions around headers in https://fetch.spec.whatwg.org/#terminology-headers. I guess I could mention there that the data structure is effectively an ordered multimap. Would that help? Going through the history might give you some answers, but not all is well explained I think. But other than that and asking questions there's not much to go on. You're always welcome on IRC https://wiki.whatwg.org/wiki/IRC to ask more of course. |
thanks for being helpful @annevk! I'll give that a go. And yes that would definitely help! 👍 |
Reopening so I don't forget to add that note. |
cool :) |
The spec is written so that headers are all ordered in the header list by their insertion time (at least request headers). For instance, should iterator retrieved from Headers provide access to key/value in the insertion order? |
@youennf I think as written order is indeed preserved. We could allow randomization of sorts I suppose at the network layer if that is warranted, but I'm not sure it is. |
It seems Chromium and Firefox are supporting insertion order for fetch, but I am not sure what is the rationale here. In WebKit, for XHR, I do not think header insertion order is supported for different header names. A HashMap to store headers is used, as well as in WebKit network layer. Using a STL-like ordered multimap would allow faster access to values if we could lessen the ordering constraint. Is there a usecase for keeping a strong ordering? service worker? router optimization? |
The reason there is ordering for We could have a discussion among browsers if we could do something that is more optimized, but please open a distinct issue for that. |
ok, thanks. |
There is probably a really simple answer to this but I'm wondering why headers isn't just an object, or another data-structure that already exists, instead of this custom type.
The text was updated successfully, but these errors were encountered: