pub struct HeaderName { /* private fields */ }Expand description
Represents an HTTP header field name
Header field names identify the header. Header sets may include multiple headers with the same name. The HTTP specification defines a number of standard headers, but HTTP messages may include non-standard header names as well as long as they adhere to the specification.
HeaderName is used as the HeaderMap key. Constants are available for
all standard header names in the header module.
Standard header constants can be used for equality checks. They cannot be
used as const patterns on stable Rust because HeaderName implements
semantic, case-insensitive PartialEq manually. If Rust stabilizes the
structural matching support needed for this representation, these constants
can become pattern-matchable again.
§Representation
HeaderName represents standard header names using an enum, as such they
will not require an allocation for storage. Header names preserve their
original casing while equality, ordering and hashing continue to use HTTP’s
case-insensitive header-name semantics.
Implementations§
Source§impl HeaderName
impl HeaderName
Sourcepub fn from_bytes(src: &[u8]) -> Result<HeaderName, InvalidHeaderName>
pub fn from_bytes(src: &[u8]) -> Result<HeaderName, InvalidHeaderName>
Converts a slice of bytes to an HTTP header name.
This function preserves the original header-name spelling while using HTTP’s case-insensitive semantics for equality and hashing.
Sourcepub fn from_lowercase(src: &[u8]) -> Result<HeaderName, InvalidHeaderName>
pub fn from_lowercase(src: &[u8]) -> Result<HeaderName, InvalidHeaderName>
Converts a slice of bytes to an HTTP header name.
This function expects the input to only contain lowercase characters. This is useful when decoding HTTP/2.0 or HTTP/3.0 headers. Both require that all headers be represented in lower case.
§Examples
// Parsing a lower case header
let hdr = HeaderName::from_lowercase(b"content-length").unwrap();
assert_eq!(CONTENT_LENGTH, hdr);
// Parsing a header that contains uppercase characters
assert!(HeaderName::from_lowercase(b"Content-Length").is_err());Sourcepub const fn from_static(src: &'static str) -> HeaderName
pub const fn from_static(src: &'static str) -> HeaderName
Converts a static string to a HTTP header name.
This function preserves the original header-name spelling while using HTTP’s case-insensitive semantics for equality and hashing.
§Panics
This function panics when the static string is a invalid header.
§Examples
// Parsing a standard header
let hdr = HeaderName::from_static("Content-Length");
assert_eq!(CONTENT_LENGTH, hdr);
// Parsing a custom header
let CUSTOM_HEADER: &'static str = "custom-header";
let a = HeaderName::from_bytes(b"Custom-Header").unwrap();
let b = HeaderName::from_static(CUSTOM_HEADER);
assert_eq!(a, b);// Parsing a header that contains invalid symbols:
HeaderName::from_static("content{}{}length"); // This line panics!Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns a str representation of the header.
Standard headers are returned in their normalized lowercase spelling. Custom headers are returned in their original spelling.
Sourcepub fn as_original_str(&self) -> Cow<'_, str>
pub fn as_original_str(&self) -> Cow<'_, str>
Returns the preserved spelling of the header name.
Standard headers with mixed or uppercase spelling may need to rebuild
their original casing from the compact case mask, so this returns
Cow. For display-only use, prefer Self::display_original.
Sourcepub fn as_lower_str(&self) -> Cow<'_, str>
pub fn as_lower_str(&self) -> Cow<'_, str>
Returns the lowercase spelling of the header name.
This borrows for standard headers and already-lowercase custom headers.
Custom headers with uppercase ASCII letters are lowercased into an owned
string. For display-only use, prefer Self::display_lowercase.
Sourcepub fn display_original(&self) -> OriginalHeaderName<'_>
pub fn display_original(&self) -> OriginalHeaderName<'_>
Returns a display adapter that writes the preserved header spelling.
Sourcepub fn display_lowercase(&self) -> LowercaseHeaderName<'_>
pub fn display_lowercase(&self) -> LowercaseHeaderName<'_>
Returns a display adapter that writes the lowercase header spelling.
This is useful for HTTP/2 and HTTP/3 diagnostics or formatting. It does not allocate.
Sourcepub fn standard(&self) -> Option<StandardHeader>
pub fn standard(&self) -> Option<StandardHeader>
Returns the standard header represented by this name, if this is a standard header.
Sourcepub fn write_original<B>(&self, dst: &mut B)where
B: BufMut,
pub fn write_original<B>(&self, dst: &mut B)where
B: BufMut,
Write the original header spelling represented by this name.
For HTTP/2 and HTTP/3 use Self::write_lowercase instead.
Sourcepub fn write_lowercase<B>(&self, dst: &mut B)where
B: BufMut,
pub fn write_lowercase<B>(&self, dst: &mut B)where
B: BufMut,
Write the lowercase wire representation required by HTTP/2 and HTTP/3.
Trait Implementations§
impl AsHeaderName for HeaderName
impl AsHeaderName for &HeaderName
Source§impl AsRef<[u8]> for HeaderName
impl AsRef<[u8]> for HeaderName
Source§impl AsRef<str> for HeaderName
impl AsRef<str> for HeaderName
Source§impl Clone for HeaderName
impl Clone for HeaderName
Source§fn clone(&self) -> HeaderName
fn clone(&self) -> HeaderName
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HeaderName
impl Debug for HeaderName
Source§impl<'de> Deserialize<'de> for HeaderName
impl<'de> Deserialize<'de> for HeaderName
Source§fn deserialize<D>(
deserializer: D,
) -> Result<HeaderName, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<HeaderName, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Display for HeaderName
impl Display for HeaderName
impl Eq for HeaderName
Source§impl From<&HeaderName> for HeaderName
impl From<&HeaderName> for HeaderName
Source§fn from(src: &HeaderName) -> HeaderName
fn from(src: &HeaderName) -> HeaderName
Source§impl From<HeaderName> for HeaderValue
impl From<HeaderName> for HeaderValue
Source§fn from(h: HeaderName) -> HeaderValue
fn from(h: HeaderName) -> HeaderValue
Source§impl From<StandardName> for HeaderName
impl From<StandardName> for HeaderName
Source§fn from(src: StandardName) -> HeaderName
fn from(src: StandardName) -> HeaderName
Source§impl FromStr for HeaderName
impl FromStr for HeaderName
Source§type Err = InvalidHeaderName
type Err = InvalidHeaderName
Source§fn from_str(s: &str) -> Result<HeaderName, InvalidHeaderName>
fn from_str(s: &str) -> Result<HeaderName, InvalidHeaderName>
s to return a value of this type. Read moreSource§impl Hash for HeaderName
impl Hash for HeaderName
impl IntoHeaderName for HeaderName
impl IntoHeaderName for &HeaderName
impl IntoHeaderName for HeaderName
Source§impl PartialEq for HeaderName
impl PartialEq for HeaderName
Source§fn eq(&self, other: &HeaderName) -> bool
fn eq(&self, other: &HeaderName) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialEq<&HeaderName> for HeaderName
impl PartialEq<&HeaderName> for HeaderName
Source§fn eq(&self, other: &&HeaderName) -> bool
fn eq(&self, other: &&HeaderName) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialEq<&HeaderName> for str
impl PartialEq<&HeaderName> for str
Source§fn eq(&self, other: &&HeaderName) -> bool
fn eq(&self, other: &&HeaderName) -> bool
Performs a case-insensitive comparison of the string against the header name
Source§impl PartialEq<&HeaderName> for String
impl PartialEq<&HeaderName> for String
Source§fn eq(&self, other: &&HeaderName) -> bool
fn eq(&self, other: &&HeaderName) -> bool
Performs a case-insensitive comparison of the string against the header name
Source§impl PartialEq<&String> for HeaderName
impl PartialEq<&String> for HeaderName
Source§impl PartialEq<&str> for HeaderName
impl PartialEq<&str> for HeaderName
Source§impl PartialEq<HeaderName> for &HeaderName
impl PartialEq<HeaderName> for &HeaderName
Source§fn eq(&self, other: &HeaderName) -> bool
fn eq(&self, other: &HeaderName) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialEq<HeaderName> for str
impl PartialEq<HeaderName> for str
Source§fn eq(&self, other: &HeaderName) -> bool
fn eq(&self, other: &HeaderName) -> bool
Performs a case-insensitive comparison of the string against the header name
§Examples
use rama_http_types::header::CONTENT_LENGTH;
assert_eq!(CONTENT_LENGTH, "content-length");
assert_eq!(CONTENT_LENGTH, "Content-Length");
assert_ne!(CONTENT_LENGTH, "content length");Source§impl PartialEq<HeaderName> for &str
impl PartialEq<HeaderName> for &str
Source§fn eq(&self, other: &HeaderName) -> bool
fn eq(&self, other: &HeaderName) -> bool
Performs a case-insensitive comparison of the string against the header name
Source§impl PartialEq<HeaderName> for String
impl PartialEq<HeaderName> for String
Source§fn eq(&self, other: &HeaderName) -> bool
fn eq(&self, other: &HeaderName) -> bool
Performs a case-insensitive comparison of the string against the header name
Source§impl PartialEq<HeaderName> for &String
impl PartialEq<HeaderName> for &String
Source§fn eq(&self, other: &HeaderName) -> bool
fn eq(&self, other: &HeaderName) -> bool
Performs a case-insensitive comparison of the string against the header name
Source§impl PartialEq<String> for HeaderName
impl PartialEq<String> for HeaderName
Source§impl PartialEq<String> for &HeaderName
impl PartialEq<String> for &HeaderName
Source§impl PartialEq<str> for HeaderName
impl PartialEq<str> for HeaderName
Source§fn eq(&self, other: &str) -> bool
fn eq(&self, other: &str) -> bool
Performs a case-insensitive comparison of the string against the header name
§Examples
use rama_http_types::header::CONTENT_LENGTH;
assert_eq!(CONTENT_LENGTH, "content-length");
assert_eq!(CONTENT_LENGTH, "Content-Length");
assert_ne!(CONTENT_LENGTH, "content length");Source§impl PartialEq<str> for &HeaderName
impl PartialEq<str> for &HeaderName
Source§impl Serialize for HeaderName
impl Serialize for HeaderName
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl TryFrom<&HeaderName> for ClientHint
impl TryFrom<&HeaderName> for ClientHint
Source§type Error = ClientHintParsingError
type Error = ClientHintParsingError
Source§fn try_from(
name: &HeaderName,
) -> Result<ClientHint, <ClientHint as TryFrom<&HeaderName>>::Error>
fn try_from( name: &HeaderName, ) -> Result<ClientHint, <ClientHint as TryFrom<&HeaderName>>::Error>
Source§impl TryFrom<&String> for HeaderName
impl TryFrom<&String> for HeaderName
Source§type Error = InvalidHeaderName
type Error = InvalidHeaderName
Source§fn try_from(
s: &String,
) -> Result<HeaderName, <HeaderName as TryFrom<&String>>::Error>
fn try_from( s: &String, ) -> Result<HeaderName, <HeaderName as TryFrom<&String>>::Error>
Source§impl TryFrom<&[u8]> for HeaderName
impl TryFrom<&[u8]> for HeaderName
Source§type Error = InvalidHeaderName
type Error = InvalidHeaderName
Source§fn try_from(
s: &[u8],
) -> Result<HeaderName, <HeaderName as TryFrom<&[u8]>>::Error>
fn try_from( s: &[u8], ) -> Result<HeaderName, <HeaderName as TryFrom<&[u8]>>::Error>
Source§impl TryFrom<&str> for HeaderName
impl TryFrom<&str> for HeaderName
Source§type Error = InvalidHeaderName
type Error = InvalidHeaderName
Source§fn try_from(s: &str) -> Result<HeaderName, <HeaderName as TryFrom<&str>>::Error>
fn try_from(s: &str) -> Result<HeaderName, <HeaderName as TryFrom<&str>>::Error>
Source§impl TryFrom<HeaderName> for ClientHint
impl TryFrom<HeaderName> for ClientHint
Source§type Error = ClientHintParsingError
type Error = ClientHintParsingError
Source§fn try_from(
name: HeaderName,
) -> Result<ClientHint, <ClientHint as TryFrom<HeaderName>>::Error>
fn try_from( name: HeaderName, ) -> Result<ClientHint, <ClientHint as TryFrom<HeaderName>>::Error>
Source§impl TryFrom<String> for HeaderName
impl TryFrom<String> for HeaderName
Source§type Error = InvalidHeaderName
type Error = InvalidHeaderName
Source§fn try_from(
s: String,
) -> Result<HeaderName, <HeaderName as TryFrom<String>>::Error>
fn try_from( s: String, ) -> Result<HeaderName, <HeaderName as TryFrom<String>>::Error>
Auto Trait Implementations§
impl !Freeze for HeaderName
impl RefUnwindSafe for HeaderName
impl Send for HeaderName
impl Sync for HeaderName
impl Unpin for HeaderName
impl UnsafeUnpin for HeaderName
impl UnwindSafe for HeaderName
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> IntoRedirectLoc for Twhere
T: IntoRedirectLocSeal,
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
Source§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.