Struct ReasonPhrase
struct ReasonPhrase(_)
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: &Self) -> &[u8]Gets the reason phrase as bytes.
const fn from_static(reason: &'static [u8]) -> SelfConverts a static byte slice to a reason phrase.
impl AsRef for ReasonPhrase
fn as_ref(self: &Self) -> &[u8]
impl Clone for ReasonPhrase
fn clone(self: &Self) -> ReasonPhrase
impl Debug for ReasonPhrase
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Eq for ReasonPhrase
impl Freeze for ReasonPhrase
impl Hash for ReasonPhrase
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl Ord for ReasonPhrase
fn cmp(self: &Self, other: &ReasonPhrase) -> Ordering
impl PartialEq for ReasonPhrase
fn eq(self: &Self, other: &ReasonPhrase) -> bool
impl PartialOrd for ReasonPhrase
fn partial_cmp(self: &Self, other: &ReasonPhrase) -> Option<Ordering>
impl RefUnwindSafe for ReasonPhrase
impl Send for ReasonPhrase
impl StructuralPartialEq for ReasonPhrase
impl Sync for ReasonPhrase
impl TryFrom for ReasonPhrase
fn try_from(reason: Vec<u8>) -> Result<Self, <Self as >::Error>
impl TryFrom for ReasonPhrase
fn try_from(reason: Bytes) -> Result<Self, <Self as >::Error>
impl TryFrom for ReasonPhrase
fn try_from(reason: String) -> Result<Self, <Self as >::Error>
impl TryFrom for ReasonPhrase
fn try_from(reason: &[u8]) -> Result<Self, <Self as >::Error>
impl Unpin for ReasonPhrase
impl UnsafeUnpin for ReasonPhrase
impl UnwindSafe for ReasonPhrase
impl<Q, K> Comparable for ReasonPhrase
fn compare(self: &Self, key: &K) -> Ordering
impl<Q, K> Equivalent for ReasonPhrase
fn equivalent(self: &Self, key: &K) -> bool
impl<Q, K> Equivalent for ReasonPhrase
fn equivalent(self: &Self, key: &K) -> bool
impl<T> Any for ReasonPhrase
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for ReasonPhrase
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for ReasonPhrase
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for ReasonPhrase
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for ReasonPhrase
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Instrument for ReasonPhrase
impl<T> ToOwned for ReasonPhrase
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> WithSubscriber for ReasonPhrase
impl<T, U> Into for ReasonPhrase
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for ReasonPhrase
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for ReasonPhrase
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>