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

Preserve header case #3

Open
lilyball opened this issue Apr 19, 2016 · 1 comment
Open

Preserve header case #3

lilyball opened this issue Apr 19, 2016 · 1 comment

Comments

@lilyball
Copy link
Collaborator

Our current mechanism for handling request headers is to normalize header names when inserting or looking them up. This means that you can say

request.headerFields["content-type"] = "application/json"
assert(request.headerFields["Content-Type"] == "application/json")

But this has two downsides:

  1. There's a (very small) performance cost for doing this. Probably negligible, but it'd still be nicer to avoid it.
  2. It doesn't preserve the case of assigned headers.

Headers are case-insensitive (which is why we do this), so not preserving the case has no functionality impacts, but it may be visible if header names are ever exposed to the user.

Note that we're already using a custom type to represent the headers, but we expose a var dictionary: [String: String] { get } property which is why we normalize instead of using a data structure that does case-insensitive comparisons. Solving this problem means doing one of the following:

  1. Calculate the dictionary value when accessing the property. This could be memoized so it's only recalculated if anything changes, but it's still not great.
  2. Get rid of the property entirely.
  3. Publicly expose CaseInsensitiveASCIIString and change the property to be [CaseInsensitiveASCIIString: String], though if we did this we'd want to extend CaseInsensitiveASCIIString to do unicode comparisons. It's also not obj-c–compatible.
  4. Define our own NSDictionary subclass that does case-insensitive comparisons and use obj-c bridging in order to use that as our data structure.
@lilyball lilyball added the TODO label Apr 19, 2016
@lilyball
Copy link
Collaborator Author

We'd want to still normalize headers defined by the HTTP/1.1 standard, it's only custom headers that should preserve case.

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

No branches or pull requests

1 participant