Struct Response
struct Response<T> { ... }
Represents an HTTP response
An HTTP response consists of a head and a potentially optional body. The body
component is generic, enabling arbitrary types to represent the HTTP body.
For example, the body could be Vec<u8>, a Stream of byte chunks, or a
value that has been deserialized.
Typically you'll work with responses on the client side as the result of
sending a Request and on the server you'll be generating a Response to
send back to the client.
Examples
Creating a Response to return
use ;
A simple 404 handler
use ;
Or otherwise inspecting the result of a request:
use http::{Request, Response};
fn get(url: &str) -> http::Result<Response<()>> {
// ...
# panic!()
}
let response = get("https://www.rust-lang.org/").unwrap();
if !response.status().is_success() {
panic!("failed to get a successful response status!");
}
if let Some(date) = response.headers().get("Date") {
// we've got a `Date` header!
}
let body = response.body();
// ...
Deserialize a response of bytes via json:
# extern crate serde;
# extern crate serde_json;
# extern crate http;
use Response;
use de;
#
#
Or alternatively, serialize the body of a response to json
# extern crate serde;
# extern crate serde_json;
# extern crate http;
use Response;
use ser;
#
#
Implementations
impl Response<()>
fn builder() -> BuilderCreates a new builder-style object to manufacture a
ResponseThis method returns an instance of
Builderwhich can be used to create aResponse.Examples
# use *; let response = builder .status .header .body .unwrap;
impl<T> Response<T>
fn new(body: T) -> Response<T>Creates a new blank
Responsewith the bodyThe component parts of this response will be set to their default, e.g. the ok status, no headers, etc.
Examples
# use *; let response = new; assert_eq!; assert_eq!;fn from_parts(parts: Parts, body: T) -> Response<T>Creates a new
Responsewith the given head and bodyExamples
# use *; let response = new; let = response.into_parts; parts.status = BAD_REQUEST; let response = from_parts; assert_eq!; assert_eq!;fn status(self: &Self) -> StatusCodeReturns the
StatusCode.Examples
# use *; let response: = default; assert_eq!;fn status_mut(self: &mut Self) -> &mut StatusCodeReturns a mutable reference to the associated
StatusCode.Examples
# use *; let mut response: = default; *response.status_mut = CREATED; assert_eq!;fn version(self: &Self) -> VersionReturns a reference to the associated version.
Examples
# use *; let response: = default; assert_eq!;fn version_mut(self: &mut Self) -> &mut VersionReturns a mutable reference to the associated version.
Examples
# use *; let mut response: = default; *response.version_mut = HTTP_2; assert_eq!;fn headers(self: &Self) -> &HeaderMap<HeaderValue>Returns a reference to the associated header field map.
Examples
# use *; let response: = default; assert!;fn headers_mut(self: &mut Self) -> &mut HeaderMap<HeaderValue>Returns a mutable reference to the associated header field map.
Examples
# use *; # use *; let mut response: = default; response.headers_mut.insert; assert!;fn extensions(self: &Self) -> &ExtensionsReturns a reference to the associated extensions.
Examples
# use *; let response: = default; assert!;fn extensions_mut(self: &mut Self) -> &mut ExtensionsReturns a mutable reference to the associated extensions.
Examples
# use *; # use *; let mut response: = default; response.extensions_mut.insert; assert_eq!;fn body(self: &Self) -> &TReturns a reference to the associated HTTP body.
Examples
# use *; let response: = default; assert!;fn body_mut(self: &mut Self) -> &mut TReturns a mutable reference to the associated HTTP body.
Examples
# use *; let mut response: = default; response.body_mut.push_str; assert!;fn into_body(self: Self) -> TConsumes the response, returning just the body.
Examples
# use Response; let response = new; let body = response.into_body; assert_eq!;fn into_parts(self: Self) -> (Parts, T)Consumes the response returning the head and body parts.
Examples
# use *; let response: = default; let = response.into_parts; assert_eq!;fn map<F, U>(self: Self, f: F) -> Response<U> where F: FnOnce(T) -> UConsumes the response returning a new response with body mapped to the return type of the passed in function.
Examples
# use *; let response = builder.body.unwrap; let mapped_response: = response.map; assert_eq!;
impl<T> Any for Response<T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Response<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Response<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Response<T>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> Freeze for Response<T>
impl<T> From for Response<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RefUnwindSafe for Response<T>
impl<T> Send for Response<T>
impl<T> Sync for Response<T>
impl<T> ToOwned for Response<T>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> Unpin for Response<T>
impl<T> UnwindSafe for Response<T>
impl<T, U> Into for Response<T>
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 Response<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Response<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T: $crate::clone::Clone> Clone for Response<T>
fn clone(self: &Self) -> Response<T>
impl<T: Default> Default for Response<T>
fn default() -> Response<T>
impl<T: fmt::Debug> Debug for Response<T>
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result