Hyper: Option to preserve header's title case

Created on 27 Oct 2020  路  4Comments  路  Source: hyperium/hyper

I am building a HTTP proxy with hyper, and I realize that headers are all converted to lower case for HTTP/1.x.

There was an issue about adding http1_title_case_headers for clients: https://github.com/hyperium/hyper/issues/1492 , but we don't have a way to preserve the response headers' title case from remote servers.

Some client applications are expecting to receive header with name that is exactly the same as the server returns, for example:

  • Nintendo Switch's connection checking will sent a GET request to http://ctest.cdn.nintendo.net/ and expecting a response with header X-Organization: Nintendo.
A-http1 B-rfc S-feature

Most helpful comment

As always, I've suggest filing a bug with the thing that expects a certain casing, since in HTTP/1 header casing is defined as case-insensitive, and in HTTP2 and 3, it's forced to lowercase. So the Switch is definitely wrong here.

That said, I realize it's not always controllable, and so I'm exploring providing support in the C API for curl, and it might be possible to expose it as part of Rust's API as well... So far, my idea is to include an extra type in the request Extensions which is a mapping of HeaderNames to the original casing. If that type exists, it would use that to serialize instead of HeaderName, and then hyper would also collect a map for the response and put that in the response Extensions.

All 4 comments

As always, I've suggest filing a bug with the thing that expects a certain casing, since in HTTP/1 header casing is defined as case-insensitive, and in HTTP2 and 3, it's forced to lowercase. So the Switch is definitely wrong here.

That said, I realize it's not always controllable, and so I'm exploring providing support in the C API for curl, and it might be possible to expose it as part of Rust's API as well... So far, my idea is to include an extra type in the request Extensions which is a mapping of HeaderNames to the original casing. If that type exists, it would use that to serialize instead of HeaderName, and then hyper would also collect a map for the response and put that in the response Extensions.

Isn't there now code to do that behind the ffi feature?

There is indeed code in hyper now, currently behind the ffi feature. If someone wants to contribute this, it'd be good to propose the API that is exposed to users, and then converting the code to be not just for the ffi feature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanmonstar picture seanmonstar  路  3Comments

toplinuxsir picture toplinuxsir  路  3Comments

da2018 picture da2018  路  3Comments

crackcomm picture crackcomm  路  5Comments

seanmonstar picture seanmonstar  路  5Comments