forked from hyperium/hyper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http1): decouple preserving header case from FFI (fixes hyperium…
…#2313) The feature is now supported in both the server and the client and can be combined with the title case feature, for headers which don't have entries in the header case map.
- Loading branch information
Showing
12 changed files
with
634 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//! HTTP extensions | ||
|
||
use bytes::Bytes; | ||
#[cfg(feature = "http1")] | ||
use http::header::{GetAll, HeaderName, IntoHeaderName}; | ||
use http::HeaderMap; | ||
|
||
/// A map from header names to their original casing as received in an HTTP message. | ||
/// | ||
/// If an HTTP/1 response `res` is parsed on a connection whose option | ||
/// [`http1_preserve_header_case`] was set to true and the response included | ||
/// the following headers: | ||
/// | ||
/// ```ignore | ||
/// x-Bread: Baguette | ||
/// X-BREAD: Pain | ||
/// x-bread: Ficelle | ||
/// ``` | ||
/// | ||
/// Then `res.extensions().get::<HeaderCaseMap>()` will return a map with: | ||
/// | ||
/// ```ignore | ||
/// HeaderCaseMap({ | ||
/// "x-bread": ["x-Bread", "X-BREAD", "x-bread"], | ||
/// }) | ||
/// ``` | ||
/// | ||
/// [`http1_preserve_header_case`]: /client/struct.Client.html#method.http1_preserve_header_case | ||
#[derive(Clone, Debug, Default)] | ||
pub struct HeaderCaseMap(HeaderMap<RawHeaderName>); | ||
|
||
#[cfg(feature = "http1")] | ||
impl HeaderCaseMap { | ||
/// Returns a view of all spellings associated with that header name, | ||
/// in the order they were found. | ||
pub fn get_all(&self, name: &HeaderName) -> GetAll<'_, RawHeaderName> { | ||
self.0.get_all(name) | ||
} | ||
|
||
#[cfg(any(test, feature = "ffi"))] | ||
pub(crate) fn insert(&mut self, name: HeaderName, orig: Bytes) { | ||
self.0.insert(name, RawHeaderName(orig)); | ||
} | ||
|
||
pub(crate) fn append<N>(&mut self, name: N, orig: Bytes) | ||
where | ||
N: IntoHeaderName, | ||
{ | ||
self.0.append(name, RawHeaderName(orig)); | ||
} | ||
} | ||
|
||
/// Represents a raw header name, which may not in lower case. | ||
/// | ||
/// Exclusively used by the `HeaderCaseMap` extension. | ||
#[derive(Clone, Debug)] | ||
pub struct RawHeaderName(Bytes); | ||
|
||
#[cfg(feature = "http1")] | ||
impl RawHeaderName { | ||
pub(crate) fn as_bytes(&self) -> &Bytes { | ||
&self.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.