Struct HeaderValue
pub struct HeaderValue { /* private fields */ }
Represents an HTTP header field value.
In practice, HTTP header field values are usually valid ASCII. However, the HTTP spec allows for a header value to contain opaque bytes as well. In this case, the header field value is not able to be represented as a string.
To handle this, the HeaderValue is usable as a type and can be compared
with strings and implements Debug. A to_str fn is provided that returns
an Err if the header value contains non visible ascii characters.
Implementations
impl HeaderValue
const fn from_static(src: &'static str) -> HeaderValueConvert a static string to a
HeaderValue.This function will not perform any copying, however the string is checked to ensure that no invalid characters are present. Only visible ASCII characters (32-127) are permitted.
Panics
This function panics if the argument contains invalid header value characters.
Examples
# use HeaderValue; let val = from_static; assert_eq!;fn from_str(src: &str) -> Result<HeaderValue, InvalidHeaderValue>Attempt to convert a string to a
HeaderValue.If the argument contains invalid header value characters, an error is returned. Only visible ASCII characters (32-127) are permitted. Use
from_bytesto create aHeaderValuethat includes opaque octets (128-255).This function is intended to be replaced in the future by a
TryFromimplementation once the trait is stabilized in std.Examples
# use HeaderValue; let val = from_str.unwrap; assert_eq!;An invalid value
# use HeaderValue; let val = from_str; assert!;fn from_name(name: HeaderName) -> HeaderValueConverts a HeaderName into a HeaderValue
Since every valid HeaderName is a valid HeaderValue this is done infallibly.
Examples
# use ; # use ACCEPT; let val = from_name; assert_eq!;fn from_bytes(src: &[u8]) -> Result<HeaderValue, InvalidHeaderValue>Attempt to convert a byte slice to a
HeaderValue.If the argument contains invalid header value bytes, an error is returned. Only byte values between 32 and 255 (inclusive) are permitted, excluding byte 127 (DEL).
This function is intended to be replaced in the future by a
TryFromimplementation once the trait is stabilized in std.Examples
# use HeaderValue; let val = from_bytes.unwrap; assert_eq!;An invalid value
# use HeaderValue; let val = from_bytes; assert!;Attempt to convert a
Bytesbuffer to aHeaderValue.This will try to prevent a copy if the type passed is the type used internally, and will copy the data if it is not.
Convert a
Bytesdirectly into aHeaderValuewithout validating.This function does NOT validate that illegal bytes are not contained within the buffer.
Panics
In a debug build this will panic if
srcis not valid UTF-8.Safety
srcmust contain valid UTF-8. In a release build it is undefined behaviour to call this withsrcthat is not valid UTF-8.fn to_str(&self) -> Result<&str, ToStrError>Yields a
&strslice if theHeaderValueonly contains visible ASCII chars.This function will perform a scan of the header value, checking all the characters.
Examples
# use HeaderValue; let val = from_static; assert_eq!;fn len(&self) -> usizeReturns the length of
self.This length is in bytes.
Examples
# use HeaderValue; let val = from_static; assert_eq!;fn is_empty(&self) -> boolReturns true if the
HeaderValuehas a length of zero bytes.Examples
# use HeaderValue; let val = from_static; assert!; let val = from_static; assert!;fn as_bytes(&self) -> &[u8]Converts a
HeaderValueto a byte slice.Examples
# use HeaderValue; let val = from_static; assert_eq!;fn set_sensitive(&mut self, val: bool)Mark that the header value represents sensitive information.
Examples
# use HeaderValue; let mut val = from_static; val.set_sensitive; assert!; val.set_sensitive; assert!;fn is_sensitive(&self) -> boolReturns
trueif the value represents sensitive data.Sensitive data could represent passwords or other data that should not be stored on disk or in memory. By marking header values as sensitive, components using this crate can be instructed to treat them with special care for security reasons. For example, caches can avoid storing sensitive values, and HPACK encoders used by HTTP/2.0 implementations can choose not to compress them.
Additionally, sensitive values will be masked by the
Debugimplementation ofHeaderValue.Note that sensitivity is not factored into equality or ordering.
Examples
# use HeaderValue; let mut val = from_static; val.set_sensitive; assert!; val.set_sensitive; assert!;
Trait Implementations
impl AsRef<[u8]> for HeaderValue
fn as_ref(&self) -> &[u8]
impl Clone for HeaderValue
fn clone(&self) -> HeaderValue
impl Debug for HeaderValue
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for HeaderValue
impl From<&HeaderValue> for HeaderValue
fn from(t: &HeaderValue) -> Self
impl From<HeaderName> for HeaderValue
fn from(h: HeaderName) -> HeaderValue
impl From<i16> for HeaderValue
fn from(num: i16) -> HeaderValue
impl From<i32> for HeaderValue
fn from(num: i32) -> HeaderValue
impl From<i64> for HeaderValue
fn from(num: i64) -> HeaderValue
impl From<isize> for HeaderValue
fn from(num: isize) -> HeaderValue
impl From<u16> for HeaderValue
fn from(num: u16) -> HeaderValue
impl From<u32> for HeaderValue
fn from(num: u32) -> HeaderValue
impl From<u64> for HeaderValue
fn from(num: u64) -> HeaderValue
impl From<usize> for HeaderValue
fn from(num: usize) -> HeaderValue
impl FromStr for HeaderValue
type Err = InvalidHeaderValue;fn from_str(s: &str) -> Result<HeaderValue, Self::Err>
impl Hash for HeaderValue
fn hash<H: Hasher>(&self, state: &mut H)
impl Ord for HeaderValue
fn cmp(&self, other: &Self) -> Ordering
impl PartialEq for HeaderValue
fn eq(&self, other: &HeaderValue) -> bool
impl PartialEq<String> for HeaderValue
fn eq(&self, other: &String) -> bool
impl PartialEq<[u8]> for HeaderValue
fn eq(&self, other: &[u8]) -> bool
impl PartialEq<str> for HeaderValue
fn eq(&self, other: &str) -> bool
impl PartialOrd for HeaderValue
fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>
impl PartialOrd<String> for HeaderValue
fn partial_cmp(&self, other: &String) -> Option<Ordering>
impl PartialOrd<[u8]> for HeaderValue
fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>
impl PartialOrd<str> for HeaderValue
fn partial_cmp(&self, other: &str) -> Option<Ordering>
impl TryFrom<&String> for HeaderValue
type Error = InvalidHeaderValue;fn try_from(s: &String) -> Result<Self, Self::Error>
impl TryFrom<&[u8]> for HeaderValue
type Error = InvalidHeaderValue;fn try_from(t: &[u8]) -> Result<Self, Self::Error>
impl TryFrom<&str> for HeaderValue
type Error = InvalidHeaderValue;fn try_from(t: &str) -> Result<Self, Self::Error>
impl TryFrom<String> for HeaderValue
type Error = InvalidHeaderValue;fn try_from(t: String) -> Result<Self, Self::Error>
impl TryFrom<Vec<u8>> for HeaderValue
type Error = InvalidHeaderValue;fn try_from(vec: Vec<u8>) -> Result<Self, Self::Error>
impl<T: ?Sized> PartialEq<&T> for HeaderValue
where
HeaderValue: PartialEq<T>,
fn eq(&self, other: &&T) -> bool
impl<T: ?Sized> PartialOrd<&T> for HeaderValue
where
HeaderValue: PartialOrd<T>,
fn partial_cmp(&self, other: &&T) -> Option<Ordering>
Auto Trait Implementations
impl !Freeze for HeaderValue
impl RefUnwindSafe for HeaderValue
impl Send for HeaderValue
impl Sync for HeaderValue
impl Unpin for HeaderValue
impl UnsafeUnpin for HeaderValue
impl UnwindSafe for HeaderValue
Blanket Implementations
impl<T> Any for HeaderValue
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for HeaderValue
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for HeaderValue
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for HeaderValue
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for HeaderValue
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for HeaderValue
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for HeaderValue
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for HeaderValue
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for HeaderValue
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>