Skip to content
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

Closed
juliankrispel opened this issue Nov 4, 2015 · 11 comments
Closed

Why are headers a special data-structure? #154

juliankrispel opened this issue Nov 4, 2015 · 11 comments

Comments

@juliankrispel
Copy link

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.

@annevk
Copy link
Member

annevk commented Nov 5, 2015

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?

@juliankrispel
Copy link
Author

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?

@annevk
Copy link
Member

annevk commented Nov 5, 2015

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.

@juliankrispel
Copy link
Author

thanks for being helpful @annevk! I'll give that a go.

And yes that would definitely help!

👍

@annevk
Copy link
Member

annevk commented Nov 5, 2015

Reopening so I don't forget to add that note.

@annevk annevk reopened this Nov 5, 2015
@juliankrispel
Copy link
Author

cool :)

@annevk annevk reopened this Nov 5, 2015
@annevk annevk closed this as completed in 3d7382b Nov 7, 2015
@youennf
Copy link
Collaborator

youennf commented Jan 5, 2016

The spec is written so that headers are all ordered in the header list by their insertion time (at least request headers).
Ordering headers with the same name makes sense.
What about the ordering between headers with different names?

For instance, should iterator retrieved from Headers provide access to key/value in the insertion order?
If a web app sets a request header (A, 1) and then a request header (B, 2), should the corresponding HTTP request try to keep the same ordering?

@annevk
Copy link
Member

annevk commented Jan 5, 2016

@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.

@youennf
Copy link
Collaborator

youennf commented Jan 5, 2016

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?

@annevk
Copy link
Member

annevk commented Jan 5, 2016

The reason there is ordering for Headers objects is that it is exposed in service workers and through iteration of Headers objects in general. Note that headers added after service workers cannot be observed other than on a server and the requirements on those are a bit muddy.

We could have a discussion among browsers if we could do something that is more optimized, but please open a distinct issue for that.

@youennf
Copy link
Collaborator

youennf commented Jan 5, 2016

ok, thanks.
Filed #189 to keep track of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants