Struct HeaderName
pub struct HeaderName { /* private fields */ }http and std only.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§
§impl HeaderName
impl HeaderName
pub 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.
pub 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());pub 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!pub 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.
pub 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.
pub 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.
pub fn display_original(&self) -> OriginalHeaderName<'_>
pub fn display_original(&self) -> OriginalHeaderName<'_>
Returns a display adapter that writes the preserved header spelling.
pub 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.
pub 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.
pub 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.
pub 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
§impl AsRef<[u8]> for HeaderName
impl AsRef<[u8]> for HeaderName
§impl AsRef<str> for HeaderName
impl AsRef<str> for HeaderName
§impl Clone for HeaderName
impl Clone for HeaderName
§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 more§impl Debug for HeaderName
impl Debug for HeaderName
§impl<'de> Deserialize<'de> for HeaderName
impl<'de> Deserialize<'de> for HeaderName
§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>,
§impl Display for HeaderName
impl Display for HeaderName
impl Eq for HeaderName
§impl From<&HeaderName> for HeaderName
impl From<&HeaderName> for HeaderName
§fn from(src: &HeaderName) -> HeaderName
fn from(src: &HeaderName) -> HeaderName
§impl From<HeaderName> for HeaderValue
impl From<HeaderName> for HeaderValue
§fn from(h: HeaderName) -> HeaderValue
fn from(h: HeaderName) -> HeaderValue
§impl From<StandardName> for HeaderName
impl From<StandardName> for HeaderName
§fn from(src: StandardName) -> HeaderName
fn from(src: StandardName) -> HeaderName
§impl FromStr for HeaderName
impl FromStr for HeaderName
§type Err = InvalidHeaderName
type Err = InvalidHeaderName
§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 more§impl Hash for HeaderName
impl Hash for HeaderName
impl IntoHeaderName for HeaderName
impl IntoHeaderName for HeaderName
impl IntoHeaderName for &HeaderName
§impl PartialEq for HeaderName
impl PartialEq for HeaderName
§impl PartialEq<&HeaderName> for HeaderName
impl PartialEq<&HeaderName> for HeaderName
§impl PartialEq<&HeaderName> for str
impl PartialEq<&HeaderName> for str
§fn eq(&self, other: &&HeaderName) -> bool
fn eq(&self, other: &&HeaderName) -> bool
Performs a case-insensitive comparison of the string against the header name
§impl PartialEq<&HeaderName> for String
impl PartialEq<&HeaderName> for String
§fn eq(&self, other: &&HeaderName) -> bool
fn eq(&self, other: &&HeaderName) -> bool
Performs a case-insensitive comparison of the string against the header name
§impl PartialEq<&String> for HeaderName
impl PartialEq<&String> for HeaderName
§impl PartialEq<&str> for HeaderName
impl PartialEq<&str> for HeaderName
§impl PartialEq<HeaderName> for &HeaderName
impl PartialEq<HeaderName> for &HeaderName
§impl PartialEq<HeaderName> for str
impl PartialEq<HeaderName> for str
§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");§impl PartialEq<HeaderName> for &str
impl PartialEq<HeaderName> for &str
§fn eq(&self, other: &HeaderName) -> bool
fn eq(&self, other: &HeaderName) -> bool
Performs a case-insensitive comparison of the string against the header name
§impl PartialEq<HeaderName> for String
impl PartialEq<HeaderName> for String
§fn eq(&self, other: &HeaderName) -> bool
fn eq(&self, other: &HeaderName) -> bool
Performs a case-insensitive comparison of the string against the header name
§impl PartialEq<HeaderName> for &String
impl PartialEq<HeaderName> for &String
§fn eq(&self, other: &HeaderName) -> bool
fn eq(&self, other: &HeaderName) -> bool
Performs a case-insensitive comparison of the string against the header name
§impl PartialEq<String> for HeaderName
impl PartialEq<String> for HeaderName
§impl PartialEq<String> for &HeaderName
impl PartialEq<String> for &HeaderName
§impl PartialEq<str> for HeaderName
impl PartialEq<str> for HeaderName
§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");§impl PartialEq<str> for &HeaderName
impl PartialEq<str> for &HeaderName
§impl Serialize for HeaderName
impl Serialize for HeaderName
§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,
§impl TryFrom<&HeaderName> for ClientHint
impl TryFrom<&HeaderName> for ClientHint
§type Error = ClientHintParsingError
type Error = ClientHintParsingError
§fn try_from(
name: &HeaderName,
) -> Result<ClientHint, <ClientHint as TryFrom<&HeaderName>>::Error>
fn try_from( name: &HeaderName, ) -> Result<ClientHint, <ClientHint as TryFrom<&HeaderName>>::Error>
§impl TryFrom<&String> for HeaderName
impl TryFrom<&String> for HeaderName
§type Error = InvalidHeaderName
type Error = InvalidHeaderName
§fn try_from(
s: &String,
) -> Result<HeaderName, <HeaderName as TryFrom<&String>>::Error>
fn try_from( s: &String, ) -> Result<HeaderName, <HeaderName as TryFrom<&String>>::Error>
§impl TryFrom<&[u8]> for HeaderName
impl TryFrom<&[u8]> for HeaderName
§type Error = InvalidHeaderName
type Error = InvalidHeaderName
§fn try_from(
s: &[u8],
) -> Result<HeaderName, <HeaderName as TryFrom<&[u8]>>::Error>
fn try_from( s: &[u8], ) -> Result<HeaderName, <HeaderName as TryFrom<&[u8]>>::Error>
§impl TryFrom<&str> for HeaderName
impl TryFrom<&str> for HeaderName
§type Error = InvalidHeaderName
type Error = InvalidHeaderName
§fn try_from(s: &str) -> Result<HeaderName, <HeaderName as TryFrom<&str>>::Error>
fn try_from(s: &str) -> Result<HeaderName, <HeaderName as TryFrom<&str>>::Error>
§impl TryFrom<HeaderName> for ClientHint
impl TryFrom<HeaderName> for ClientHint
§type Error = ClientHintParsingError
type Error = ClientHintParsingError
§fn try_from(
name: HeaderName,
) -> Result<ClientHint, <ClientHint as TryFrom<HeaderName>>::Error>
fn try_from( name: HeaderName, ) -> Result<ClientHint, <ClientHint as TryFrom<HeaderName>>::Error>
§impl TryFrom<String> for HeaderName
impl TryFrom<String> for HeaderName
§type Error = InvalidHeaderName
type Error = InvalidHeaderName
§fn try_from(
s: String,
) -> Result<HeaderName, <HeaderName as TryFrom<String>>::Error>
fn try_from( s: String, ) -> Result<HeaderName, <HeaderName as TryFrom<String>>::Error>
§impl TryFrom<Vec<u8>> for HeaderName
impl TryFrom<Vec<u8>> for HeaderName
§type Error = InvalidHeaderName
type Error = InvalidHeaderName
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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§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>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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,
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>
§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)§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.
§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writer§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writer§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writer§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writer§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer