Struct hyper::ext::ReasonPhrase
source · [−]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
sourceimpl ReasonPhrase
impl ReasonPhrase
sourcepub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Gets the reason phrase as bytes.
sourcepub fn from_static(reason: &'static [u8]) -> Self
pub fn from_static(reason: &'static [u8]) -> Self
Converts a static byte slice to a reason phrase.
sourcepub unsafe fn from_bytes_unchecked(reason: Bytes) -> Self
pub unsafe fn from_bytes_unchecked(reason: Bytes) -> Self
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
sourceimpl AsRef<[u8]> for ReasonPhrase
impl AsRef<[u8]> for ReasonPhrase
sourceimpl Clone for ReasonPhrase
impl Clone for ReasonPhrase
sourcefn clone(&self) -> ReasonPhrase
fn clone(&self) -> ReasonPhrase
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for ReasonPhrase
impl Debug for ReasonPhrase
sourceimpl Hash for ReasonPhrase
impl Hash for ReasonPhrase
sourceimpl Into<Bytes> for ReasonPhrase
impl Into<Bytes> for ReasonPhrase
sourceimpl Ord for ReasonPhrase
impl Ord for ReasonPhrase
sourcefn cmp(&self, other: &ReasonPhrase) -> Ordering
fn cmp(&self, other: &ReasonPhrase) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialEq<ReasonPhrase> for ReasonPhrase
impl PartialEq<ReasonPhrase> for ReasonPhrase
sourcefn eq(&self, other: &ReasonPhrase) -> bool
fn eq(&self, other: &ReasonPhrase) -> bool
sourceimpl PartialOrd<ReasonPhrase> for ReasonPhrase
impl PartialOrd<ReasonPhrase> for ReasonPhrase
sourcefn partial_cmp(&self, other: &ReasonPhrase) -> Option<Ordering>
fn partial_cmp(&self, other: &ReasonPhrase) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more