#[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) -> Self
pub fn new(method: Method, uri: Uri) -> Self
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: TryInto<Uri>>(uri: U) -> Result<Self, <U as TryInto<Uri>>::Error>
pub fn get<U: TryInto<Uri>>(uri: U) -> Result<Self, <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: TryInto<Uri>>(uri: U) -> Result<Self, <U as TryInto<Uri>>::Error>
pub fn put<U: TryInto<Uri>>(uri: U) -> Result<Self, <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: TryInto<Uri>>(uri: U) -> Result<Self, <U as TryInto<Uri>>::Error>
pub fn post<U: TryInto<Uri>>(uri: U) -> Result<Self, <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: TryInto<Uri>>(
uri: U,
) -> Result<Self, <U as TryInto<Uri>>::Error>
pub fn delete<U: TryInto<Uri>>( uri: U, ) -> Result<Self, <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: TryInto<Uri>>(
uri: U,
) -> Result<Self, <U as TryInto<Uri>>::Error>
pub fn patch<U: TryInto<Uri>>( uri: U, ) -> Result<Self, <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: TryInto<Uri>>(uri: U) -> Result<Self, <U as TryInto<Uri>>::Error>
pub fn head<U: TryInto<Uri>>(uri: U) -> Result<Self, <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<Self, Error>where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Error: From<<K as TryInto<HeaderName>>::Error> + From<<V as TryInto<HeaderValue>>::Error>,
pub fn header<K, V>(self, name: K, value: V) -> Result<Self, Error>where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Error: 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) -> Self
pub fn connect_timeout(self, timeout: Duration) -> Self
Set the connect_timeout.
Sourcepub fn low_speed_timeout(
self,
timeout: Duration,
bytes_per_sec: ByteLength,
) -> Self
pub fn low_speed_timeout( self, timeout: Duration, bytes_per_sec: ByteLength, ) -> Self
Set the low_speed_timeout.
Sourcepub fn redirect_limit(self, count: u16) -> Self
pub fn redirect_limit(self, count: u16) -> Self
Set the redirect_limit.
Sourcepub fn auto_decompress(self, enabled: bool) -> Self
pub fn auto_decompress(self, enabled: bool) -> Self
Set the auto_decompress.
Sourcepub fn require_length(self, enabled: bool) -> Self
pub fn require_length(self, enabled: bool) -> Self
Set require_length.
Sourcepub fn max_length(self, max: ByteLength) -> Self
pub fn max_length(self, max: ByteLength) -> Self
Set max_length.
Sourcepub fn max_upload_speed(self, bytes_per_sec: ByteLength) -> Self
pub fn max_upload_speed(self, bytes_per_sec: ByteLength) -> Self
Set the max_upload_speed.
Sourcepub fn max_download_speed(self, bytes_per_sec: ByteLength) -> Self
pub fn max_download_speed(self, bytes_per_sec: ByteLength) -> Self
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<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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> 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