Skip to main content

Request

Struct Request 

Source
pub struct Request {
    pub method: Method,
    pub url: String,
    pub headers: Vec<(String, String)>,
    pub body: Vec<u8>,
    pub timeout: Option<Duration>,
    pub retry: Option<RetryPolicy>,
    pub retry_unsafe_statuses: bool,
    /* private fields */
}

Fields§

§method: Method§url: String§headers: Vec<(String, String)>§body: Vec<u8>§timeout: Option<Duration>

Per-attempt total timeout (buffered calls and stream headers).

§retry: Option<RetryPolicy>§retry_unsafe_statuses: bool

Allow retrying a POST/PATCH after HTTP-status failures (429, 5xx, …). Default false since 0.3.0: a replayed POST (a single-use OAuth code exchange, a payment) can be harmful. Transport errors on non-idempotent methods retry only in the connect phase regardless. Set true per request for an idempotent POST; see the README for how this interacts with RetryPolicy::none().

Implementations§

Source§

impl Request

Source

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

Source

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

Source

pub fn post(url: impl Into<String>) -> Self

Source

pub fn put(url: impl Into<String>) -> Self

Source

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

Source

pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self

Append a header. Use Request::set_header to replace an existing one.

Source

pub fn set_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self

Set a header, replacing every existing header with the same name (ASCII case-insensitive). The first occurrence keeps its position.

Source

pub fn secret_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self

Set a header whose value is a secret. The value is sent on the wire but never appears in error text, retry events, or Debug output.

Source

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

Authorization: Bearer <token>. The token is treated as a secret.

Source

pub fn redact_value(self, value: impl Into<String>) -> Self

Register a secret that is not a header, for example a form field or a value inside a body. It is scrubbed from error text, retry events and Debug output exactly like a Request::secret_header value. Empty values are ignored.

Source

pub fn secret_form(self, pairs: &[(&str, &str)], secret_names: &[&str]) -> Self

Request::form that also registers the value of every pair whose name is in secret_names (compared ignoring ASCII case) as a secret, so a token or client secret sent in the body is scrubbed from errors like a secret header.

Source

pub fn scrub(&self, text: &str) -> String

Replace every secret value registered on this request (not the client’s configured ones) in text with [redacted]. For text the caller took from a response, such as an error field a provider echoed back, where no HTTP error carries it for scrubbing.

Source

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

Source

pub fn json<T: Serialize>(self, value: &T) -> Result<Self, HttpError>

Source

pub fn form(self, pairs: &[(&str, &str)]) -> Self

application/x-www-form-urlencoded body.

Source

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

Per-attempt total timeout. Each retry attempt gets this budget; use Request::deadline to bound all attempts together.

Source

pub fn deadline(self, total: Duration) -> Self

Overall budget for the call: all attempts and the retry sleeps between them. When the next sleep would pass the deadline, the last outcome is returned instead of sleeping. The per-attempt timeout is unchanged.

Source

pub fn retry(self, policy: RetryPolicy) -> Self

Source

pub fn retry_unsafe_statuses(self, allow: bool) -> Self

Allow retrying POST/PATCH after HTTP-status failures (true) or not (false, the default).

Source

pub fn max_response_bytes(self, limit: usize) -> Self

Per-request response body limit, overriding ClientConfig::max_response_bytes.

Source

pub fn headers_only(self) -> Self

Return only the status and headers: send, send_any and Client::send_headers do not read the response body. It is dropped unread, which closes that connection. Any status is returned by send_any and send_headers, including 3xx when redirects are off and 4xx/5xx after retries; send still turns non-2xx into an error.

Source

pub fn cancel(self, token: CancelToken) -> Self

Cancel this call through token. Checked between attempts, during retry sleeps and before every body read; a cancelled call returns HttpError::Cancelled.

Source§

impl Request

Source

pub fn multipart(self, form: Multipart) -> Result<Self, HttpError>

Set the body and Content-Type from a multipart form (replacing any existing Content-Type).

Source§

impl Request

Set the body and Content-Type from a multipart/related body (replacing any existing Content-Type).

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