Skip to main content

Request

Struct Request 

Source
pub struct Request { /* private fields */ }
Expand description

A request under construction. Build with Request::get (and friends), then fetch or a Client.

Implementations§

Source§

impl Request

Source

pub fn conditional(self, validators: &CacheValidators) -> Self

Revalidate a locally stored GET/HEAD representation on every backend. Installs If-None-Match and If-Modified-Since (ETag takes precedence at compliant servers). Replaces existing copies of these headers. Does not add preconditions to mutations. This is independent of the platform HTTP cache and does not turn a 304 into a 200.

Source§

impl Request

Source

pub fn new(method: Method, url: impl Into<String>) -> Request

A request with this method.

Source

pub fn get(url: impl Into<String>) -> Request

Source

pub fn post(url: impl Into<String>, body: Vec<u8>) -> Request

Source

pub fn put(url: impl Into<String>, body: Vec<u8>) -> Request

Source

pub fn delete(url: impl Into<String>) -> Request

Source

pub fn patch(url: impl Into<String>, body: Vec<u8>) -> Request

Source

pub fn head(url: impl Into<String>) -> Request

Source

pub fn method(&self) -> Method

The method.

Source

pub fn url(&self) -> &str

The URL, as given.

Source

pub fn headers(&self) -> &[(String, String)]

The request headers, in the order they were added.

Source

pub fn header(self, name: &str, value: &str) -> Self

Append a request header (duplicates allowed, sent in order).

Source

pub fn bearer(self, token: &str) -> Self

Authorization: Bearer <token>, sent up front.

Source

pub fn basic_auth(self, user: &str, password: &str) -> Self

Authorization: Basic …, sent up front instead of waiting for a challenge.

Source

pub fn body(self, bytes: Vec<u8>) -> Self

The request body (also settable via the Request::post/Request::put/Request::patch constructors).

Source

pub fn body_file(self, path: impl Into<PathBuf>) -> Self

Send a file as the body, read while it is sent. A Client only.

Source

pub fn body_stream( self, reader: impl Read + Send + 'static, len: Option<u64>, ) -> Self

Send what reader yields as the body, read while it is sent. len becomes Content-Length; without it the body goes out chunked where the platform allows. A stream can be sent once, so a redirect or challenge that needs the body again fails the request. A Client only.

Source

pub fn form(self, form: Form) -> Self

Send a multipart/form-data body; its Content-Type is set unless the request sets one. A Client only.

Source

pub fn timeout(self, d: Duration) -> Self

How long the request may sit without progress. Default 30 s. This bounds connecting, awaiting the response head, and idle gaps in the body, not the total transfer time, so a long download that keeps moving is never cut off (per-platform mapping: docs/http.md).

Source

pub fn timeout_total(self, d: Duration) -> Self

How long the whole request may take, redirects, challenges and body included. A Client only; it overrides ClientBuilder::timeout_total.

Source

pub fn allow_expensive(self, allowed: bool) -> Self

Whether the request may use “expensive” paths (cellular / personal hotspot). Default true. Native on Apple (allowsExpensiveNetworkAccess); advisory elsewhere; combine with day_part_connectivity::status().expensive for app-side policy.

Source

pub fn allow_constrained(self, allowed: bool) -> Self

Whether the request may run under Low Data Mode. Default true. Native on Apple (allowsConstrainedNetworkAccess); advisory elsewhere.

Source

pub fn cache(self, policy: CachePolicy) -> Self

How the request may use the client’s cache. Default CachePolicy::Default.

Source

pub fn priority(self, priority: f32) -> Self

A scheduling hint from 0.0 (lowest) to 1.0 (highest), where the platform takes one.

Source

pub fn protocols<S: Into<String>>( self, protocols: impl IntoIterator<Item = S>, ) -> Self

WebSocket subprotocols to offer, in preference order.

Source

pub fn upload_progress( self, observe: impl Fn(u64, Option<u64>) + Send + Sync + 'static, ) -> Self

Observe the body going out: (bytes sent, total), on the thread the platform reports on. Needs Capabilities::upload_progress. A Client only.

Trait Implementations§

Source§

impl Clone for Request

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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

Formats the value using the given formatter. 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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.