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

X-<Header> converts to lowercase #228

Closed
crusty-dave opened this issue Jul 14, 2018 · 2 comments
Closed

X-<Header> converts to lowercase #228

crusty-dave opened this issue Jul 14, 2018 · 2 comments

Comments

@crusty-dave
Copy link

crusty-dave commented Jul 14, 2018

With the following code:

Ok(HttpResponse::Ok() .header("X-Subject-Token", token.token) .body(""))

It transmits "X-Subject-Token" as "x-subject-token", this would seem to be a bug, it shouldn't be changing any header tags like this AFAIK?

Per RFC 7230, the headers should be case-insensitive, but I would still expect http to honor the case that I have provided.

RFC 7230

3.2. Header Fields

Each header field consists of a case-insensitive field name followed
by a colon (":"), optional leading whitespace, the field value, and
optional trailing whitespace.

Note that the HTTP RFCs use camel-case with dash (-) separators when they describe the fields.

This is the first time that I have witnessed something like "content-type" instead of "Content-Type".

I would think that this might cause some compatibility issues with some http processors if they ignored section 3.2 (I ran into some code with that issue). So at the least, there should be an option to preserve Camel-Case if present IMO.

@carllerche
Copy link
Collaborator

Thanks for the report.

The HTTP crate internally normalizes to lower case in order to implement a number of performance optimizations. As you quoted, the spec defines HTTP header fields as being case-insensitive.

The http crate has no plans to add support for maintaining header name case as this would introduce a performance regression for all users.

It is possible for HTTP client and server implementations to add features supporting invalid HTTP peers without the http crate doing anything. If you hit a real interopt problem, I would suggest opening an issue with the client / server you are using.

I'm going to close this issue as there is no further action for us to take.

@seanmonstar
Copy link
Member

As you've pointed out, RFC 7230 says names are case-insensitive, so should be perfectly valid to treat X-Subject-Token as x-subject-token. Additionally, in HTTP/2, all header names are lowercase (it's specified to be a protocol error for upper case names). Because of this, HeaderName chooses to always handle names as lower case. Doing this allows optimizations: case-insensitive hashing and comparison are no longer required, improving speed of inserts and searches in the HeaderMap.

Notably, HeaderName is just an optimized holder of a header name string. HTTP implementations certainly can transform the name bytes to camel case before serializing to a network stream, For example, hyper provides an option to do just that, for when users actually do have to deal with bad HTTP implementations. In hyper, it isn't enabled by default, since there's a cost to transforming the bytes, and most HTTP implementations are good-ish, and handle header names correctly.

You could ask actix-web to provide such an option.

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

No branches or pull requests

3 participants