Struct ReasonPhrase

pub struct ReasonPhrase(/* private field */);

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.

# #[cfg(all(feature = "tcp", feature = "client", feature = "http1"))]
# async fn fake_fetch() -> hyper::Result<()> {
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());
}
# Ok(())
# }

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

impl ReasonPhrase

fn as_bytes(&self) -> &[u8]

Gets the reason phrase as bytes.

const fn from_static(reason: &'static [u8]) -> Self

Converts a static byte slice to a reason phrase.

Trait Implementations

impl AsRef<[u8]> for ReasonPhrase

fn as_ref(&self) -> &[u8]

impl Clone for ReasonPhrase

fn clone(&self) -> ReasonPhrase

impl Debug for ReasonPhrase

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Eq for ReasonPhrase

impl Hash for ReasonPhrase

fn hash<__H: Hasher>(&self, state: &mut __H)

impl Ord for ReasonPhrase

fn cmp(&self, other: &ReasonPhrase) -> Ordering

impl PartialEq for ReasonPhrase

fn eq(&self, other: &ReasonPhrase) -> bool

impl PartialOrd for ReasonPhrase

fn partial_cmp(&self, other: &ReasonPhrase) -> Option<Ordering>

impl StructuralPartialEq for ReasonPhrase

impl TryFrom<&[u8]> for ReasonPhrase

type Error = InvalidReasonPhrase;
fn try_from(reason: &[u8]) -> Result<Self, Self::Error>

impl TryFrom<Bytes> for ReasonPhrase

type Error = InvalidReasonPhrase;
fn try_from(reason: Bytes) -> Result<Self, Self::Error>

impl TryFrom<String> for ReasonPhrase

type Error = InvalidReasonPhrase;
fn try_from(reason: String) -> Result<Self, Self::Error>

impl TryFrom<Vec<u8>> for ReasonPhrase

type Error = InvalidReasonPhrase;
fn try_from(reason: Vec<u8>) -> Result<Self, Self::Error>

Auto Trait Implementations

impl !Freeze for ReasonPhrase

impl RefUnwindSafe for ReasonPhrase

impl Send for ReasonPhrase

impl Sync for ReasonPhrase

impl Unpin for ReasonPhrase

impl UnsafeUnpin for ReasonPhrase

impl UnwindSafe for ReasonPhrase

Blanket Implementations

impl<Q, K> Comparable<K> for ReasonPhrase where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

fn compare(&self, key: &K) -> Ordering

impl<Q, K> Equivalent<K> for ReasonPhrase where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

fn equivalent(&self, key: &K) -> bool

impl<Q, K> Equivalent<K> for ReasonPhrase where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

fn equivalent(&self, key: &K) -> bool

impl<T> Any for ReasonPhrase where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for ReasonPhrase where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for ReasonPhrase where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for ReasonPhrase where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for ReasonPhrase

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for ReasonPhrase

impl<T> ToOwned for ReasonPhrase where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> WithSubscriber for ReasonPhrase

impl<T, U> Into<U> for ReasonPhrase where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for ReasonPhrase where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for ReasonPhrase where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>