Struct Request
struct Request<T> { ... }
Represents an HTTP request.
An HTTP request 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.
Examples
Creating a Request to send
use http::{Request, Response};
let mut request = Request::builder()
.uri("https://www.rust-lang.org/")
.header("User-Agent", "my-awesome-agent/1.0");
if needs_awesome_header() {
request = request.header("Awesome", "yes");
}
let response = send(request.body(()).unwrap());
# fn needs_awesome_header() -> bool {
# true
# }
#
fn send(req: Request<()>) -> Response<()> {
// ...
# panic!()
}
Inspecting a request to see what was sent.
use ;
Deserialize a request of bytes via json:
# extern crate serde;
# extern crate serde_json;
# extern crate http;
use Request;
use de;
#
#
Or alternatively, serialize the body of a request to json
# extern crate serde;
# extern crate serde_json;
# extern crate http;
use Request;
use ser;
#
#
Implementations
impl Request<()>
fn builder() -> BuilderCreates a new builder-style object to manufacture a
RequestThis method returns an instance of
Builderwhich can be used to create aRequest.Examples
# use *; let request = builder .method .uri .header .body .unwrap;fn get<T>(uri: T) -> Builder where T: TryInto<Uri>, <T as TryInto<Uri>>::Error: Into<crate::Error>Creates a new
Builderinitialized with a GET method and the given URI.This method returns an instance of
Builderwhich can be used to create aRequest.Example
# use *; let request = get .body .unwrap;fn put<T>(uri: T) -> Builder where T: TryInto<Uri>, <T as TryInto<Uri>>::Error: Into<crate::Error>Creates a new
Builderinitialized with a PUT method and the given URI.This method returns an instance of
Builderwhich can be used to create aRequest.Example
# use *; let request = put .body .unwrap;fn post<T>(uri: T) -> Builder where T: TryInto<Uri>, <T as TryInto<Uri>>::Error: Into<crate::Error>Creates a new
Builderinitialized with a POST method and the given URI.This method returns an instance of
Builderwhich can be used to create aRequest.Example
# use *; let request = post .body .unwrap;fn delete<T>(uri: T) -> Builder where T: TryInto<Uri>, <T as TryInto<Uri>>::Error: Into<crate::Error>Creates a new
Builderinitialized with a DELETE method and the given URI.This method returns an instance of
Builderwhich can be used to create aRequest.Example
# use *; let request = delete .body .unwrap;fn options<T>(uri: T) -> Builder where T: TryInto<Uri>, <T as TryInto<Uri>>::Error: Into<crate::Error>Creates a new
Builderinitialized with an OPTIONS method and the given URI.This method returns an instance of
Builderwhich can be used to create aRequest.Example
# use *; let request = options .body .unwrap; # assert_eq!;fn head<T>(uri: T) -> Builder where T: TryInto<Uri>, <T as TryInto<Uri>>::Error: Into<crate::Error>Creates a new
Builderinitialized with a HEAD method and the given URI.This method returns an instance of
Builderwhich can be used to create aRequest.Example
# use *; let request = head .body .unwrap;fn connect<T>(uri: T) -> Builder where T: TryInto<Uri>, <T as TryInto<Uri>>::Error: Into<crate::Error>Creates a new
Builderinitialized with a CONNECT method and the given URI.This method returns an instance of
Builderwhich can be used to create aRequest.Example
# use *; let request = connect .body .unwrap;fn patch<T>(uri: T) -> Builder where T: TryInto<Uri>, <T as TryInto<Uri>>::Error: Into<crate::Error>Creates a new
Builderinitialized with a PATCH method and the given URI.This method returns an instance of
Builderwhich can be used to create aRequest.Example
# use *; let request = patch .body .unwrap;fn trace<T>(uri: T) -> Builder where T: TryInto<Uri>, <T as TryInto<Uri>>::Error: Into<crate::Error>Creates a new
Builderinitialized with a TRACE method and the given URI.This method returns an instance of
Builderwhich can be used to create aRequest.Example
# use *; let request = trace .body .unwrap;
impl<T> Request<T>
fn new(body: T) -> Request<T>Creates a new blank
Requestwith the bodyThe component parts of this request will be set to their default, e.g. the GET method, no headers, etc.
Examples
# use *; let request = new; assert_eq!; assert_eq!;fn from_parts(parts: Parts, body: T) -> Request<T>Creates a new
Requestwith the given components parts and body.Examples
# use *; let request = new; let = request.into_parts; parts.method = POST; let request = from_parts;fn method(self: &Self) -> &MethodReturns a reference to the associated HTTP method.
Examples
# use *; let request: = default; assert_eq!;fn method_mut(self: &mut Self) -> &mut MethodReturns a mutable reference to the associated HTTP method.
Examples
# use *; let mut request: = default; *request.method_mut = PUT; assert_eq!;fn uri(self: &Self) -> &UriReturns a reference to the associated URI.
Examples
# use *; let request: = default; assert_eq!;fn uri_mut(self: &mut Self) -> &mut UriReturns a mutable reference to the associated URI.
Examples
# use *; let mut request: = default; *request.uri_mut = "/hello".parse.unwrap; assert_eq!;fn version(self: &Self) -> VersionReturns the associated version.
Examples
# use *; let request: = default; assert_eq!;fn version_mut(self: &mut Self) -> &mut VersionReturns a mutable reference to the associated version.
Examples
# use *; let mut request: = default; *request.version_mut = HTTP_2; assert_eq!;fn headers(self: &Self) -> &HeaderMap<HeaderValue>Returns a reference to the associated header field map.
Examples
# use *; let request: = 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 request: = default; request.headers_mut.insert; assert!;fn extensions(self: &Self) -> &ExtensionsReturns a reference to the associated extensions.
Examples
# use *; let request: = default; assert!;fn extensions_mut(self: &mut Self) -> &mut ExtensionsReturns a mutable reference to the associated extensions.
Examples
# use *; # use *; let mut request: = default; request.extensions_mut.insert; assert_eq!;fn body(self: &Self) -> &TReturns a reference to the associated HTTP body.
Examples
# use *; let request: = default; assert!;fn body_mut(self: &mut Self) -> &mut TReturns a mutable reference to the associated HTTP body.
Examples
# use *; let mut request: = default; request.body_mut.push_str; assert!;fn into_body(self: Self) -> TConsumes the request, returning just the body.
Examples
# use Request; let request = new; let body = request.into_body; assert_eq!;fn into_parts(self: Self) -> (Parts, T)Consumes the request returning the head and body parts.
Examples
# use *; let request = new; let = request.into_parts; assert_eq!;fn map<F, U>(self: Self, f: F) -> Request<U> where F: FnOnce(T) -> UConsumes the request returning a new request with body mapped to the return type of the passed in function.
Examples
# use *; let request = builder.body.unwrap; let mapped_request: = request.map; assert_eq!;
impl<T> Any for Request<T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Request<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Request<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Request<T>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> Freeze for Request<T>
impl<T> From for Request<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RefUnwindSafe for Request<T>
impl<T> Send for Request<T>
impl<T> Sync for Request<T>
impl<T> ToOwned for Request<T>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> Unpin for Request<T>
impl<T> UnwindSafe for Request<T>
impl<T, U> Into for Request<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 Request<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Request<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T: $crate::clone::Clone> Clone for Request<T>
fn clone(self: &Self) -> Request<T>
impl<T: Default> Default for Request<T>
fn default() -> Request<T>
impl<T: fmt::Debug> Debug for Request<T>
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result