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 Clone for ReasonPhrase
impl Clone for ReasonPhrase
sourcefn clone(&self) -> ReasonPhrase
fn clone(&self) -> ReasonPhrase
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl 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
sourceimpl PartialEq<ReasonPhrase> for ReasonPhrase
impl PartialEq<ReasonPhrase> for ReasonPhrase
sourcefn eq(&self, other: &ReasonPhrase) -> bool
fn eq(&self, other: &ReasonPhrase) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &ReasonPhrase) -> bool
fn ne(&self, other: &ReasonPhrase) -> bool
This method tests for !=
.
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>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl TryFrom<Bytes> for ReasonPhrase
impl TryFrom<Bytes> for ReasonPhrase
sourceimpl TryFrom<String> for ReasonPhrase
impl TryFrom<String> for ReasonPhrase
impl Eq for ReasonPhrase
impl StructuralEq for ReasonPhrase
impl StructuralPartialEq for ReasonPhrase
Auto Trait Implementations
impl RefUnwindSafe for ReasonPhrase
impl Send for ReasonPhrase
impl Sync for ReasonPhrase
impl Unpin for ReasonPhrase
impl UnwindSafe for ReasonPhrase
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more