Struct HeaderValue Copy item path Source pub struct HeaderValue { }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. to_str returns an
error if the value is not valid UTF-8.
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 HTAB and
visible ASCII characters (32-126) 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" );Attempt to convert a string to a HeaderValue.
If the argument contains invalid header value characters, an error is
returned. The same bytes as in from_bytes are
permitted, so non-ASCII characters are accepted.
§ Examples
let val = HeaderValue::from_str("hello" ).unwrap();
assert_eq! (val, "hello" );
let val = HeaderValue::from_str("caf\u{e9}" ).unwrap();
assert_eq! (val.to_str().unwrap(), "caf\u{e9}" );
An invalid value
let val = HeaderValue::from_str("\n" );
assert! (val.is_err());Attempt to convert a byte slice to a HeaderValue.
If the argument contains invalid header value bytes, an error is
returned. Only HTAB and byte values between 32 and 255 (inclusive) are
permitted, excluding byte 127 (DEL).
§ 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.
The conversion avoids copying when src can be converted into the
internal Bytes representation without allocation. The same bytes as
in from_bytes are permitted.
Creates a header value from bytes without validation.
§ Safety
src must contain only bytes allowed in an HTTP header field value:
HTAB and bytes 32 through 255, excluding 127.
Yields a &str slice if the HeaderValue is valid UTF-8.
This function validates the whole header value as UTF-8.
§ Examples
let val = HeaderValue::from_static("hello" );
assert_eq! (val.to_str().unwrap(), "hello" );
let val = HeaderValue::from_bytes(b"caf\xe9" ).unwrap();
assert! (val.to_str().is_err());Returns the length of self.
This length is in bytes.
§ Examples
let val = HeaderValue::from_static("hello" );
assert_eq! (val.len(), 5 );Returns true if the header value is empty.
§ Examples
let val = HeaderValue::from_static("" );
assert! (val.is_empty());
let val = HeaderValue::from_static("hello" );
assert! (!val.is_empty());Returns the header value as a byte slice.
§ Examples
let val = HeaderValue::from_static("hello" );
assert_eq! (val.as_bytes(), b"hello" );Returns the underlying shared byte buffer.
§ Examples
let val = HeaderValue::from_static("hello" );
assert_eq! (val.as_shared(), & Bytes::from_static(b"hello" ));Marks whether the header value contains 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());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. 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 Debug
implementation of HeaderValue.
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());Converts this type into a shared reference of the (usually inferred) input type.
Performs copy-assignment from
source.
Read more Formats the value using the given formatter.
Read more Deserialize this value from the given Serde deserializer.
Read more Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string
s to return a value of this type.
Read more Compares and returns the maximum of two values.
Read more Compares and returns the minimum of two values.
Read more Restrict a value to a certain interval.
Read more 🔬 This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more Serialize this value into the given Serde serializer.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from
self to
dest.
Read more Returns the argument unchanged.
Calls U::from(self).
That is, this conversion is whatever the implementation of
From <T> for U chooses to do.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.