Header fields should be case insensitive (RFC 7230 §3.2, RFC 9110 §5.1)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.4k
- Forks
- 378
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 5
Description
I'm working with http::HeaderMap and noticed that HeaderMap::get, HeaderMap::insert, and HeaderName::from_static all seem to be case sensitive (in fact, the latter panics:
HeaderName::from_static("Content-Type")
panics with:
index out of bounds: the len is 0 but the index is 0
while:
HeaderName::from_static("content-type")
does not.
This goes against the HTTP spec requiring case-insensitive handling of header values:
- RFC 7230 §3.2
Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace.
- RFC 9110 §5.1
Field names are case-insensitive...
IMO, this is distinct from #670, and in fact case-insensitive keys should solve that issue as well, while not requiring the original cases to be changed.
It looks like crates like case_insensitive_hashmap and unicase are examples of case-insensitive String handling.
Is there any way to just make the HeaderMap case-insensitive for retrieval? That would preserve original case as well as allow any case for HeaderMap::get to meet the spec and prevent errors.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the HeaderMap::get and HeaderMap::insert behavior together with HeaderName::from_static, using the case-sensitive examples in the issue as the reproduction. Done means header-name retrieval accepts differing capitalization, from_static no longer panics for valid field names, and original casing remains preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100