Skip to content

Conversation

@kotx
Copy link

@kotx kotx commented Oct 28, 2025

Addresses #2695 by exposing a public API for HeaderCaseMap
Basically we validate the original spelling bytes by just parsing it as a HeaderName.
Maybe we need to further validate by comparing equivalence? But I'm not sure.

First time contributing to Hyper, let me know if there are issues!

src/ext/mod.rs Outdated
/// Inserts a header spelling, replacing any existing ones associated with that header name.
#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
pub fn insert(&mut self, name: HeaderName, orig: Bytes) -> Result<(), InvalidHeaderName> {
HeaderName::from_bytes(&orig)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever! Hm, at the same time, it worries me a little to be validating, not parsing. It does mean a user can't round trip from get_all to insert without having to validate again.

At the same time, is it really worth having a separate CasedHeaderName type? Maybe it is... This is probably the hardest question with making this public.

Also, I think HeaderName::from_bytes() will allocate a new copy... That could probably be handled with from_maybe_shared, but just wanted to note for myself at least.

Copy link
Author

@kotx kotx Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HeaderName doesn't seem to have from_maybe_shared, that seems to be exclusive to HeaderValue?

Anyway, I added a CasedHeaderName type. Usage is a bit clunky since its used like .insert(CasedHeaderName::new(name, orig).unwrap()).

There's also a From<Bytes> implementation that infers the header name by parsing it.
The ::new(HeaderName, Bytes) constructor checks that the provided Bytes matches the supplied HeaderName.

This comment was marked as resolved.

@kotx kotx marked this pull request as draft November 13, 2025 21:26
@kotx kotx marked this pull request as ready for review November 13, 2025 21:38
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

Successfully merging this pull request may close these issues.

2 participants