pub struct ReasonPhrase(_);
Expand description

A reason phrase in an HTTP/1 response.

Clients

For clients, a ReasonPhrase will be present in the extensions of the http::Response returned for a request if the reason phrase is different from the canonical reason phrase for the response’s status code. For example, if a server returns HTTP/1.1 200 Awesome, the ReasonPhrase will be present and contain Awesome, but if a server returns HTTP/1.1 200 OK, the response will not contain a ReasonPhrase.

use hyper::{Client, Uri};
use hyper::ext::ReasonPhrase;

let res = Client::new().get(Uri::from_static("http://example.com/non_canonical_reason")).await?;

// Print out the non-canonical reason phrase, if it has one...
if let Some(reason) = res.extensions().get::<ReasonPhrase>() {
    println!("non-canonical reason: {}", std::str::from_utf8(reason.as_bytes()).unwrap());
}

Servers

When a ReasonPhrase is present in the extensions of the http::Response written by a server, its contents will be written in place of the canonical reason phrase when responding via HTTP/1.

Implementations

Gets the reason phrase as bytes.

Converts a static byte slice to a reason phrase.

Converts a Bytes directly into a ReasonPhrase without validating.

Use with care; invalid bytes in a reason phrase can cause serious security problems if emitted in a response.

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

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

Converts this type into the (usually inferred) input type.

This method returns an Ordering between self and other. 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 method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

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

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

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. 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.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more