Struct http::header::HeaderValue [] [src]

pub struct HeaderValue { /* fields omitted */ }

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.

Methods

impl HeaderValue
[src]

[src]

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");

[src]

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());

[src]

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());

[src]

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.

[src]

Convert a Bytes directly into a HeaderValue without validating.

This function does NOT validate that illegal bytes are not contained within the buffer.

[src]

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");

[src]

Returns the length of self.

This length is in bytes.

Examples

let val = HeaderValue::from_static("hello");
assert_eq!(val.len(), 5);

[src]

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());

[src]

Converts a HeaderValue to a byte slice.

Examples

let val = HeaderValue::from_static("hello");
assert_eq!(val.as_bytes(), b"hello");

[src]

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());

[src]

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

impl Clone for HeaderValue
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Hash for HeaderValue
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl AsRef<[u8]> for HeaderValue
[src]

[src]

Performs the conversion.

impl Debug for HeaderValue
[src]

[src]

Formats the value using the given formatter.

impl FromStr for HeaderValue
[src]

The associated error which can be returned from parsing.

[src]

Parses a string s to return a value of this type. Read more

impl<'a> HttpTryFrom<&'a str> for HeaderValue
[src]

Associated error with the conversion this implementation represents.

[src]

impl<'a> HttpTryFrom<&'a [u8]> for HeaderValue
[src]

Associated error with the conversion this implementation represents.

[src]

impl HttpTryFrom<Bytes> for HeaderValue
[src]

Associated error with the conversion this implementation represents.

[src]

impl PartialEq for HeaderValue
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl Eq for HeaderValue
[src]

impl PartialOrd for HeaderValue
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for HeaderValue
[src]

[src]

This method returns an Ordering between self and other. Read more

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

impl PartialEq<str> for HeaderValue
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl PartialEq<[u8]> for HeaderValue
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl PartialOrd<str> for HeaderValue
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<[u8]> for HeaderValue
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq<String> for HeaderValue
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl PartialOrd<String> for HeaderValue
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> PartialEq<HeaderValue> for &'a HeaderValue
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a> PartialOrd<HeaderValue> for &'a HeaderValue
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a, T: ?Sized> PartialEq<&'a T> for HeaderValue where
    HeaderValue: PartialEq<T>, 
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a, T: ?Sized> PartialOrd<&'a T> for HeaderValue where
    HeaderValue: PartialOrd<T>, 
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl HttpTryFrom<HeaderValue> for HeaderValue
[src]

Associated error with the conversion this implementation represents.

[src]