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
impl Request
Sourcepub fn conditional(self, validators: &CacheValidators) -> Self
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
impl Request
pub fn get(url: impl Into<String>) -> Request
pub fn post(url: impl Into<String>, body: Vec<u8>) -> Request
pub fn put(url: impl Into<String>, body: Vec<u8>) -> Request
pub fn delete(url: impl Into<String>) -> Request
pub fn patch(url: impl Into<String>, body: Vec<u8>) -> Request
pub fn head(url: impl Into<String>) -> Request
Sourcepub fn headers(&self) -> &[(String, String)]
pub fn headers(&self) -> &[(String, String)]
The request headers, in the order they were added.
Sourcepub fn header(self, name: &str, value: &str) -> Self
pub fn header(self, name: &str, value: &str) -> Self
Append a request header (duplicates allowed, sent in order).
Sourcepub fn basic_auth(self, user: &str, password: &str) -> Self
pub fn basic_auth(self, user: &str, password: &str) -> Self
Authorization: Basic …, sent up front instead of waiting for a challenge.
Sourcepub fn body(self, bytes: Vec<u8>) -> Self
pub fn body(self, bytes: Vec<u8>) -> Self
The request body (also settable via the Request::post/Request::put/Request::patch
constructors).
Sourcepub fn body_file(self, path: impl Into<PathBuf>) -> Self
pub fn body_file(self, path: impl Into<PathBuf>) -> Self
Send a file as the body, read while it is sent. A Client only.
Sourcepub fn body_stream(
self,
reader: impl Read + Send + 'static,
len: Option<u64>,
) -> Self
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.
Sourcepub fn form(self, form: Form) -> Self
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.
Sourcepub fn timeout(self, d: Duration) -> Self
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).
Sourcepub fn timeout_total(self, d: Duration) -> Self
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.
Sourcepub fn allow_expensive(self, allowed: bool) -> Self
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.
Sourcepub fn allow_constrained(self, allowed: bool) -> Self
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.
Sourcepub fn cache(self, policy: CachePolicy) -> Self
pub fn cache(self, policy: CachePolicy) -> Self
How the request may use the client’s cache. Default CachePolicy::Default.
Sourcepub fn priority(self, priority: f32) -> Self
pub fn priority(self, priority: f32) -> Self
A scheduling hint from 0.0 (lowest) to 1.0 (highest), where the platform takes one.
Sourcepub fn protocols<S: Into<String>>(
self,
protocols: impl IntoIterator<Item = S>,
) -> Self
pub fn protocols<S: Into<String>>( self, protocols: impl IntoIterator<Item = S>, ) -> Self
WebSocket subprotocols to offer, in preference order.
Sourcepub fn upload_progress(
self,
observe: impl Fn(u64, Option<u64>) + Send + Sync + 'static,
) -> Self
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.