Request

Struct Request 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§uri: Uri

The URI.

§method: Method

The HTTP method.

§headers: HeaderMap

Header values.

Is empty by default.

§timeout: Duration

Maximum 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: Duration

Maximum 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: u16

Maximum redirects to follow.

When redirecting the Referer header is updated automatically.

Is 20 by default.

§auto_decompress: bool

If 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: ByteLength

Maximum upload speed in bytes per second.

No maximum by default, ByteLength::MAX.

§max_download_speed: ByteLength

Maximum download speed in bytes per second.

No maximum by default, ByteLength::MAX.

§require_length: bool

If the Content-Length header must be present in the response.

By default this is not required.

§max_length: ByteLength

Set 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: CacheMode

Response cache mode.

Is CacheMode::Default by default.

§cookies: bool

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: bool

If transfer metrics should be measured.

When enabled you can get the information using the Response::metrics method.

This is enabled by default.

§body: IpcBytes

Request body content.

Is empty by default.

Implementations§

Source§

impl Request

Source

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()?);
Source

pub fn get<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
where U: TryInto<Uri>,

Starts building a GET request.

§Examples
use zng_task::http;

let get = http::Request::get("https://httpbin.org/get")?;
Source

pub fn put<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
where U: TryInto<Uri>,

Starts building a PUT request.

§Examples
use zng_task::http;

let put = http::Request::put("https://httpbin.org/put")?.header("accept", "application/json")?;
Source

pub fn post<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
where U: TryInto<Uri>,

Starts building a POST request.

§Examples
use zng_task::http;

let post = http::Request::post("https://httpbin.org/post")?.header("accept", "application/json")?;
Source

pub fn delete<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
where U: TryInto<Uri>,

Starts building a DELETE request.

§Examples
use zng_task::http;

let delete = http::Request::delete("https://httpbin.org/delete")?.header("accept", "application/json")?;
Source

pub fn patch<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
where U: TryInto<Uri>,

Starts building a PATCH request.

§Examples
use zng_task::http;

let patch = http::Request::patch("https://httpbin.org/patch")?.header("accept", "application/json")?;
Source

pub fn head<U>(uri: U) -> Result<Request, <U as TryInto<Uri>>::Error>
where U: TryInto<Uri>,

Starts building a HEAD request.

§Examples
use zng_task::http;

let head = http::Request::head("https://httpbin.org")?;
Source

pub fn header<K, V>( self, name: K, value: V, ) -> Result<Request, Box<dyn Error + Sync + Send>>

Appends a header to headers to this request.

Source

pub fn timeout(self, timeout: Duration) -> Request

Set the timeout.

Source

pub fn connect_timeout(self, timeout: Duration) -> Request

Set the connect_timeout.

Source

pub fn low_speed_timeout( self, timeout: Duration, bytes_per_sec: ByteLength, ) -> Request

Source

pub fn redirect_limit(self, count: u16) -> Request

Set the redirect_limit.

Source

pub fn auto_decompress(self, enabled: bool) -> Request

Set the auto_decompress.

Source

pub fn require_length(self, enabled: bool) -> Request

Source

pub fn max_length(self, max: ByteLength) -> Request

Source

pub fn max_upload_speed(self, bytes_per_sec: ByteLength) -> Request

Source

pub fn max_download_speed(self, bytes_per_sec: ByteLength) -> Request

Source

pub fn cookies(self, enable: bool) -> Request

Set the cookies.

Source

pub fn metrics(self, enabled: bool) -> Request

Set the metrics.

Source

pub fn body(self, body: IpcBytes) -> Request

Set the body.

Source

pub fn body_text( self, body: &str, ) -> Result<Request, Box<dyn Error + Sync + Send>>

Set the body to a plain text UTF-8 payload. Also sets the Content-Type header if it is not set.

Source

pub fn body_json<T>( self, body: &T, ) -> Result<Request, Box<dyn Error + Sync + Send>>
where T: Serialize,

Set the body to a JSON payload. Also sets the Content-Type header if it is not set.

Trait Implementations§

Source§

impl Clone for Request

Source§

fn clone(&self) -> Request

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Request

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Request

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Request, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Request<IpcBytes>> for Request

Source§

fn from(value: Request<IpcBytes>) -> Request

Converts to this type from the input type.
Source§

impl RequestLike for Request

Source§

fn uri(&self) -> Uri

Same as req.uri().clone()
Source§

fn is_same_uri(&self, other: &Uri) -> bool

Whether the effective request URI matches the other URI Read more
Source§

fn method(&self) -> &Method

Same as req.method()
Source§

fn headers(&self) -> &HeaderMap

Same as req.headers()
Source§

impl Serialize for Request

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FsChangeNote for T
where T: Debug + Any + Send + Sync,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Access any.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> IpcValue for T
where T: Serialize + for<'d> Deserialize<'d> + Send + 'static,

Source§

impl<T> StateValue for T
where T: Any + Send + Sync,