#[non_exhaustive]pub struct Request {Show 16 fields
pub uri: Uri,
pub method: Method,
pub headers: HeaderMap,
pub timeout: Duration,
pub connect_timeout: Duration,
pub low_speed_timeout: (Duration, ByteLength),
pub redirect_limit: u16,
pub auto_decompress: bool,
pub max_upload_speed: ByteLength,
pub max_download_speed: ByteLength,
pub require_length: bool,
pub max_length: ByteLength,
pub cache: CacheMode,
pub cookies: bool,
pub metrics: bool,
pub body: IpcBytes,
}Expand description
HTTP request.
Use send to send a request.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.uri: UriThe URI.
method: MethodThe HTTP method.
headers: HeaderMapHeader values.
Is empty by default.
timeout: DurationMaximum amount of time that a complete request/response cycle is allowed to take before being aborted. This includes DNS resolution, connecting to the server, writing the request, and reading the response.
Note that this includes the response read operation, so if you get a response but don’t
read-it within this timeout you will get a TimedOut IO error.
By default no timeout is used, Duration::MAX.
connect_timeout: DurationMaximum amount of time to await for establishing connections to a host.
Is 90 seconds by default.
low_speed_timeout: (Duration, ByteLength)Maximum amount of time allowed when transfer speed is under the given speed in bytes per second.
By default not timeout is used, (Duration::MAX, 0).
redirect_limit: u16Maximum redirects to follow.
When redirecting the Referer header is updated automatically.
Is 20 by default.
auto_decompress: boolIf should auto decompress received data.
If enabled the “Accept-Encoding” will also be set automatically, if it was not set on the header.
This is enabled by default.
max_upload_speed: ByteLengthMaximum upload speed in bytes per second.
No maximum by default, ByteLength::MAX.
max_download_speed: ByteLengthMaximum download speed in bytes per second.
No maximum by default, ByteLength::MAX.
require_length: boolIf the Content-Length header must be present in the response.
By default this is not required.
max_length: ByteLengthSet the maximum response content length allowed.
If the Content-Length is present on the response and it exceeds this limit an error is
returned immediately, otherwise if require_length is not enabled an error will be returned
only when the downloaded body length exceeds the limit.
By default no limit is set, ByteLength::MAX.
cache: CacheModeResponse cache mode.
Is CacheMode::Default by default.
If cookies should be send and stored.
When enabled the http_cache is used to retrieve and store cookies.
Is not enabled by default.
metrics: boolIf transfer metrics should be measured.
When enabled you can get the information using the Response::metrics method.
This is enabled by default.
body: IpcBytesRequest body content.
Is empty by default.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(method: Method, uri: Uri) -> Request
pub fn new(method: Method, uri: Uri) -> Request
Starts building a request.
§Examples
use zng_task::http;
let request = http::Request::new(http::Method::PUT, "https://httpbin.org/put".try_into()?);Sourcepub fn get<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
pub fn get<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
Starts building a GET request.
§Examples
use zng_task::http;
let get = http::Request::get("https://httpbin.org/get")?;Sourcepub fn put<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
pub fn put<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
Starts building a PUT request.
§Examples
use zng_task::http;
let put = http::Request::put("https://httpbin.org/put")?.header("accept", "application/json")?;Sourcepub fn post<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
pub fn post<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
Starts building a POST request.
§Examples
use zng_task::http;
let post = http::Request::post("https://httpbin.org/post")?.header("accept", "application/json")?;Sourcepub fn delete<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
pub fn delete<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
Starts building a DELETE request.
§Examples
use zng_task::http;
let delete = http::Request::delete("https://httpbin.org/delete")?.header("accept", "application/json")?;Sourcepub fn patch<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
pub fn patch<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
Starts building a PATCH request.
§Examples
use zng_task::http;
let patch = http::Request::patch("https://httpbin.org/patch")?.header("accept", "application/json")?;Sourcepub fn head<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
pub fn head<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
Starts building a HEAD request.
§Examples
use zng_task::http;
let head = http::Request::head("https://httpbin.org")?;Sourcepub fn header<K, V>(
self,
name: K,
value: V,
) -> Result<Request, Box<dyn Error + Sync + Send>>where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Box<dyn Error + Sync + Send>: From<<K as TryInto<HeaderName>>::Error> + From<<V as TryInto<HeaderValue>>::Error>,
pub fn header<K, V>(
self,
name: K,
value: V,
) -> Result<Request, Box<dyn Error + Sync + Send>>where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Box<dyn Error + Sync + Send>: From<<K as TryInto<HeaderName>>::Error> + From<<V as TryInto<HeaderValue>>::Error>,
Appends a header to headers to this request.
Sourcepub fn connect_timeout(self, timeout: Duration) -> Request
pub fn connect_timeout(self, timeout: Duration) -> Request
Set the connect_timeout.
Sourcepub fn low_speed_timeout(
self,
timeout: Duration,
bytes_per_sec: ByteLength,
) -> Request
pub fn low_speed_timeout( self, timeout: Duration, bytes_per_sec: ByteLength, ) -> Request
Set the low_speed_timeout.
Sourcepub fn redirect_limit(self, count: u16) -> Request
pub fn redirect_limit(self, count: u16) -> Request
Set the redirect_limit.
Sourcepub fn auto_decompress(self, enabled: bool) -> Request
pub fn auto_decompress(self, enabled: bool) -> Request
Set the auto_decompress.
Sourcepub fn require_length(self, enabled: bool) -> Request
pub fn require_length(self, enabled: bool) -> Request
Set require_length.
Sourcepub fn max_length(self, max: ByteLength) -> Request
pub fn max_length(self, max: ByteLength) -> Request
Set max_length.
Sourcepub fn max_upload_speed(self, bytes_per_sec: ByteLength) -> Request
pub fn max_upload_speed(self, bytes_per_sec: ByteLength) -> Request
Set the max_upload_speed.
Sourcepub fn max_download_speed(self, bytes_per_sec: ByteLength) -> Request
pub fn max_download_speed(self, bytes_per_sec: ByteLength) -> Request
Set the max_download_speed.
Set the cookies.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Request
impl<'de> Deserialize<'de> for Request
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Request, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Request, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Request
impl Serialize for Request
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl !Freeze for Request
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnwindSafe for Request
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more