pub struct HeaderValue { /* private fields */ }Expand description
A string that can be used to represent an header value
HeaderValue contains raw bytes that are guaranteed 1 to
contain a valid header value that meets the following requirements:
- The value does not contain
\ror\nbytes
The value may be empty and may contain arbitrary non-UTF-8 bytes:
the NATS server relays header values verbatim, and other clients
(like nats.go) are able to produce such values.
HeaderValue can be constructed from HeaderValue::from_static,
HeaderValue::from_bytes, or any of the TryFrom implementations.
Because
HeaderValue::from_dangerous_valueis safe to call, unsafe code must not assume any of the above invariants. ↩
Implementations§
Source§impl HeaderValue
impl HeaderValue
Sourcepub fn from_static(value: &'static str) -> Self
pub fn from_static(value: &'static str) -> Self
Sourcepub fn from_bytes(value: &[u8]) -> Result<Self, HeaderValueValidateError>
pub fn from_bytes(value: &[u8]) -> Result<Self, HeaderValueValidateError>
Construct a HeaderValue from raw bytes, validating the value
§Errors
Returns an error if value contains \r or \n.
Sourcepub fn from_dangerous_value(value: Bytes) -> Self
pub fn from_dangerous_value(value: Bytes) -> Self
Construct a HeaderValue from a Bytes, without checking invariants
This method bypasses invariants checks implemented by HeaderValue::from_static,
HeaderValue::from_bytes, and all TryFrom implementations.
§Security
While calling this method can eliminate the runtime performance cost of
checking the value, constructing HeaderValue with an invalid value and
then calling the NATS server with it can cause serious security issues.
When in doubt use HeaderValue::from_static, HeaderValue::from_bytes,
or any of the TryFrom implementations.
Sourcepub fn to_str(&self) -> Result<&str, HeaderValueToStrError>
pub fn to_str(&self) -> Result<&str, HeaderValueToStrError>
Try to view this header value as a &str
§Errors
Returns HeaderValueToStrError if the value contains bytes that are
not valid UTF-8.
Trait Implementations§
Source§impl AsRef<[u8]> for HeaderValue
impl AsRef<[u8]> for HeaderValue
Source§impl Clone for HeaderValue
impl Clone for HeaderValue
Source§fn clone(&self) -> HeaderValue
fn clone(&self) -> HeaderValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more