Struct reqwest::header::HeaderValue
source · [−]pub struct HeaderValue { /* private fields */ }
Expand description
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 useable 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
sourceimpl HeaderValue
impl HeaderValue
sourcepub fn from_static(src: &'static str) -> HeaderValue
pub fn from_static(src: &'static str) -> HeaderValue
Convert 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
let val = HeaderValue::from_static("hello");
assert_eq!(val, "hello");
sourcepub fn from_str(src: &str) -> Result<HeaderValue, InvalidHeaderValue>
pub 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_bytes
to create a HeaderValue
that includes opaque octets
(128-255).
This function is intended to be replaced in the future by a TryFrom
implementation once the trait is stabilized in std.
Examples
let val = HeaderValue::from_str("hello").unwrap();
assert_eq!(val, "hello");
An invalid value
let val = HeaderValue::from_str("\n");
assert!(val.is_err());
sourcepub fn from_name(name: HeaderName) -> HeaderValue
pub fn from_name(name: HeaderName) -> HeaderValue
Converts a HeaderName into a HeaderValue
Since every valid HeaderName is a valid HeaderValue this is done infallibly.
Examples
let val = HeaderValue::from_name(ACCEPT);
assert_eq!(val, HeaderValue::from_bytes(b"accept").unwrap());
sourcepub fn from_bytes(src: &[u8]) -> Result<HeaderValue, InvalidHeaderValue>
pub 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 TryFrom
implementation once the trait is stabilized in std.
Examples
let val = HeaderValue::from_bytes(b"hello\xfa").unwrap();
assert_eq!(val, &b"hello\xfa"[..]);
An invalid value
let val = HeaderValue::from_bytes(b"\n");
assert!(val.is_err());
Attempt to convert a Bytes
buffer 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 TryFrom
implementation once the trait is stabilized in std.
Convert a Bytes
directly into a HeaderValue
without validating.
This function does NOT validate that illegal bytes are not contained within the buffer.
sourcepub fn to_str(&self) -> Result<&str, ToStrError>
pub fn to_str(&self) -> Result<&str, ToStrError>
Yields a &str
slice if the HeaderValue
only contains visible ASCII
chars.
This function will perform a scan of the header value, checking all the characters.
Examples
let val = HeaderValue::from_static("hello");
assert_eq!(val.to_str().unwrap(), "hello");
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of self
.
This length is in bytes.
Examples
let val = HeaderValue::from_static("hello");
assert_eq!(val.len(), 5);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the HeaderValue
has a length of zero bytes.
Examples
let val = HeaderValue::from_static("");
assert!(val.is_empty());
let val = HeaderValue::from_static("hello");
assert!(!val.is_empty());
sourcepub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
Converts a HeaderValue
to a byte slice.
Examples
let val = HeaderValue::from_static("hello");
assert_eq!(val.as_bytes(), b"hello");
sourcepub fn set_sensitive(&mut self, val: bool)
pub fn set_sensitive(&mut self, val: bool)
Mark that the header value represents sensitive information.
Examples
let mut val = HeaderValue::from_static("my secret");
val.set_sensitive(true);
assert!(val.is_sensitive());
val.set_sensitive(false);
assert!(!val.is_sensitive());
sourcepub fn is_sensitive(&self) -> bool
pub fn is_sensitive(&self) -> bool
Returns true
if the value represents sensitive data.
Sensitive data could represent passwords or other data that should not
be stored on disk or in memory. This setting can be used by components
like caches to avoid storing the value. HPACK encoders must set the
header field to never index when is_sensitive
returns true.
Note that sensitivity is not factored into equality or ordering.
Examples
let mut val = HeaderValue::from_static("my secret");
val.set_sensitive(true);
assert!(val.is_sensitive());
val.set_sensitive(false);
assert!(!val.is_sensitive());
Trait Implementations
sourceimpl Clone for HeaderValue
impl Clone for HeaderValue
sourcepub fn clone(&self) -> HeaderValue
pub fn clone(&self) -> HeaderValue
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for HeaderValue
impl Debug for HeaderValue
sourceimpl<'a> From<&'a HeaderValue> for HeaderValue
impl<'a> From<&'a HeaderValue> for HeaderValue
sourcepub fn from(t: &'a HeaderValue) -> HeaderValue
pub fn from(t: &'a HeaderValue) -> HeaderValue
Performs the conversion.
sourceimpl From<HeaderName> for HeaderValue
impl From<HeaderName> for HeaderValue
sourcepub fn from(h: HeaderName) -> HeaderValue
pub fn from(h: HeaderName) -> HeaderValue
Performs the conversion.
sourceimpl From<i16> for HeaderValue
impl From<i16> for HeaderValue
sourcepub fn from(num: i16) -> HeaderValue
pub fn from(num: i16) -> HeaderValue
Performs the conversion.
sourceimpl From<i32> for HeaderValue
impl From<i32> for HeaderValue
sourcepub fn from(num: i32) -> HeaderValue
pub fn from(num: i32) -> HeaderValue
Performs the conversion.
sourceimpl From<i64> for HeaderValue
impl From<i64> for HeaderValue
sourcepub fn from(num: i64) -> HeaderValue
pub fn from(num: i64) -> HeaderValue
Performs the conversion.
sourceimpl From<isize> for HeaderValue
impl From<isize> for HeaderValue
sourcepub fn from(num: isize) -> HeaderValue
pub fn from(num: isize) -> HeaderValue
Performs the conversion.
sourceimpl From<u16> for HeaderValue
impl From<u16> for HeaderValue
sourcepub fn from(num: u16) -> HeaderValue
pub fn from(num: u16) -> HeaderValue
Performs the conversion.
sourceimpl From<u32> for HeaderValue
impl From<u32> for HeaderValue
sourcepub fn from(num: u32) -> HeaderValue
pub fn from(num: u32) -> HeaderValue
Performs the conversion.
sourceimpl From<u64> for HeaderValue
impl From<u64> for HeaderValue
sourcepub fn from(num: u64) -> HeaderValue
pub fn from(num: u64) -> HeaderValue
Performs the conversion.
sourceimpl From<usize> for HeaderValue
impl From<usize> for HeaderValue
sourcepub fn from(num: usize) -> HeaderValue
pub fn from(num: usize) -> HeaderValue
Performs the conversion.
sourceimpl FromStr for HeaderValue
impl FromStr for HeaderValue
type Err = InvalidHeaderValue
type Err = InvalidHeaderValue
The associated error which can be returned from parsing.
sourcepub fn from_str(s: &str) -> Result<HeaderValue, <HeaderValue as FromStr>::Err>
pub fn from_str(s: &str) -> Result<HeaderValue, <HeaderValue as FromStr>::Err>
Parses a string s
to return a value of this type. Read more
sourceimpl Hash for HeaderValue
impl Hash for HeaderValue
sourceimpl<'a> HttpTryFrom<&'a [u8]> for HeaderValue
impl<'a> HttpTryFrom<&'a [u8]> for HeaderValue
type Error = InvalidHeaderValue
type Error = InvalidHeaderValue
Associated error with the conversion this implementation represents.
pub fn try_from(
t: &'a [u8]
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<&'a [u8]>>::Error>
sourceimpl<'a> HttpTryFrom<&'a HeaderValue> for HeaderValue
impl<'a> HttpTryFrom<&'a HeaderValue> for HeaderValue
type Error = Never
type Error = Never
Associated error with the conversion this implementation represents.
pub fn try_from(
t: &'a HeaderValue
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<&'a HeaderValue>>::Error>
sourceimpl<'a> HttpTryFrom<&'a String> for HeaderValue
impl<'a> HttpTryFrom<&'a String> for HeaderValue
type Error = InvalidHeaderValue
type Error = InvalidHeaderValue
Associated error with the conversion this implementation represents.
pub fn try_from(
s: &'a String
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<&'a String>>::Error>
sourceimpl<'a> HttpTryFrom<&'a str> for HeaderValue
impl<'a> HttpTryFrom<&'a str> for HeaderValue
type Error = InvalidHeaderValue
type Error = InvalidHeaderValue
Associated error with the conversion this implementation represents.
pub fn try_from(
t: &'a str
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<&'a str>>::Error>
sourceimpl HttpTryFrom<Bytes> for HeaderValue
impl HttpTryFrom<Bytes> for HeaderValue
type Error = InvalidHeaderValueBytes
type Error = InvalidHeaderValueBytes
Associated error with the conversion this implementation represents.
pub fn try_from(
bytes: Bytes
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<Bytes>>::Error>
sourceimpl HttpTryFrom<HeaderName> for HeaderValue
impl HttpTryFrom<HeaderName> for HeaderValue
type Error = InvalidHeaderValue
type Error = InvalidHeaderValue
Associated error with the conversion this implementation represents.
pub fn try_from(
name: HeaderName
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<HeaderName>>::Error>
sourceimpl HttpTryFrom<HeaderValue> for HeaderValue
impl HttpTryFrom<HeaderValue> for HeaderValue
pub fn try_from(
t: HeaderValue
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<HeaderValue>>::Error>
sourceimpl HttpTryFrom<String> for HeaderValue
impl HttpTryFrom<String> for HeaderValue
type Error = InvalidHeaderValueBytes
type Error = InvalidHeaderValueBytes
Associated error with the conversion this implementation represents.
pub fn try_from(
t: String
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<String>>::Error>
sourceimpl HttpTryFrom<i16> for HeaderValue
impl HttpTryFrom<i16> for HeaderValue
type Error = Never
type Error = Never
Associated error with the conversion this implementation represents.
pub fn try_from(
num: i16
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<i16>>::Error>
sourceimpl HttpTryFrom<i32> for HeaderValue
impl HttpTryFrom<i32> for HeaderValue
type Error = Never
type Error = Never
Associated error with the conversion this implementation represents.
pub fn try_from(
num: i32
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<i32>>::Error>
sourceimpl HttpTryFrom<i64> for HeaderValue
impl HttpTryFrom<i64> for HeaderValue
type Error = Never
type Error = Never
Associated error with the conversion this implementation represents.
pub fn try_from(
num: i64
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<i64>>::Error>
sourceimpl HttpTryFrom<isize> for HeaderValue
impl HttpTryFrom<isize> for HeaderValue
type Error = Never
type Error = Never
Associated error with the conversion this implementation represents.
pub fn try_from(
num: isize
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<isize>>::Error>
sourceimpl HttpTryFrom<u16> for HeaderValue
impl HttpTryFrom<u16> for HeaderValue
type Error = Never
type Error = Never
Associated error with the conversion this implementation represents.
pub fn try_from(
num: u16
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<u16>>::Error>
sourceimpl HttpTryFrom<u32> for HeaderValue
impl HttpTryFrom<u32> for HeaderValue
type Error = Never
type Error = Never
Associated error with the conversion this implementation represents.
pub fn try_from(
num: u32
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<u32>>::Error>
sourceimpl HttpTryFrom<u64> for HeaderValue
impl HttpTryFrom<u64> for HeaderValue
type Error = Never
type Error = Never
Associated error with the conversion this implementation represents.
pub fn try_from(
num: u64
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<u64>>::Error>
sourceimpl HttpTryFrom<usize> for HeaderValue
impl HttpTryFrom<usize> for HeaderValue
type Error = Never
type Error = Never
Associated error with the conversion this implementation represents.
pub fn try_from(
num: usize
) -> Result<HeaderValue, <HeaderValue as HttpTryFrom<usize>>::Error>
sourceimpl Ord for HeaderValue
impl Ord for HeaderValue
sourceimpl<'a, T> PartialEq<&'a T> for HeaderValue where
T: ?Sized,
HeaderValue: PartialEq<T>,
impl<'a, T> PartialEq<&'a T> for HeaderValue where
T: ?Sized,
HeaderValue: PartialEq<T>,
sourceimpl PartialEq<HeaderValue> for HeaderValue
impl PartialEq<HeaderValue> for HeaderValue
sourceimpl<'a> PartialEq<HeaderValue> for &'a str
impl<'a> PartialEq<HeaderValue> for &'a str
sourceimpl<'a> PartialEq<HeaderValue> for &'a HeaderValue
impl<'a> PartialEq<HeaderValue> for &'a HeaderValue
sourceimpl PartialEq<HeaderValue> for str
impl PartialEq<HeaderValue> for str
sourceimpl PartialEq<String> for HeaderValue
impl PartialEq<String> for HeaderValue
sourceimpl PartialEq<str> for HeaderValue
impl PartialEq<str> for HeaderValue
sourceimpl<'a, T> PartialOrd<&'a T> for HeaderValue where
T: ?Sized,
HeaderValue: PartialOrd<T>,
impl<'a, T> PartialOrd<&'a T> for HeaderValue where
T: ?Sized,
HeaderValue: PartialOrd<T>,
sourcepub fn partial_cmp(&self, other: &&'a T) -> Option<Ordering>
pub fn partial_cmp(&self, other: &&'a T) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<[u8]> for HeaderValue
impl PartialOrd<[u8]> for HeaderValue
sourcepub fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>
pub fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<'a> PartialOrd<HeaderValue> for &'a str
impl<'a> PartialOrd<HeaderValue> for &'a str
sourcepub fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>
pub fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<HeaderValue> for str
impl PartialOrd<HeaderValue> for str
sourcepub fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>
pub fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<HeaderValue> for HeaderValue
impl PartialOrd<HeaderValue> for HeaderValue
sourcepub fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>
pub fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<HeaderValue> for [u8]
impl PartialOrd<HeaderValue> for [u8]
sourcepub fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>
pub fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<'a> PartialOrd<HeaderValue> for &'a HeaderValue
impl<'a> PartialOrd<HeaderValue> for &'a HeaderValue
sourcepub fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>
pub fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<String> for HeaderValue
impl PartialOrd<String> for HeaderValue
sourcepub fn partial_cmp(&self, other: &String) -> Option<Ordering>
pub fn partial_cmp(&self, other: &String) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<str> for HeaderValue
impl PartialOrd<str> for HeaderValue
sourcepub fn partial_cmp(&self, other: &str) -> Option<Ordering>
pub fn partial_cmp(&self, other: &str) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for HeaderValue
Auto Trait Implementations
impl RefUnwindSafe for HeaderValue
impl Send for HeaderValue
impl Sync for HeaderValue
impl Unpin for HeaderValue
impl UnwindSafe for HeaderValue
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcepub fn equivalent(&self, key: &K) -> bool
pub fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more