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: boolAllow 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
impl Request
pub fn new(method: Method, url: impl Into<String>) -> Self
pub fn get(url: impl Into<String>) -> Self
pub fn post(url: impl Into<String>) -> Self
pub fn put(url: impl Into<String>) -> Self
pub fn delete(url: impl Into<String>) -> Self
Sourcepub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
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.
Sourcepub fn set_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
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.
Sourcepub fn secret_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
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.
Sourcepub fn bearer(self, token: &str) -> Self
pub fn bearer(self, token: &str) -> Self
Authorization: Bearer <token>. The token is treated as a secret.
Sourcepub fn redact_value(self, value: impl Into<String>) -> Self
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.
Sourcepub fn secret_form(self, pairs: &[(&str, &str)], secret_names: &[&str]) -> Self
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.
Sourcepub fn scrub(&self, text: &str) -> String
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.
pub fn body(self, body: impl Into<Vec<u8>>) -> Self
pub fn json<T: Serialize>(self, value: &T) -> Result<Self, HttpError>
Sourcepub fn timeout(self, d: Duration) -> Self
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.
Sourcepub fn deadline(self, total: Duration) -> Self
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.
pub fn retry(self, policy: RetryPolicy) -> Self
Sourcepub fn retry_unsafe_statuses(self, allow: bool) -> Self
pub fn retry_unsafe_statuses(self, allow: bool) -> Self
Allow retrying POST/PATCH after HTTP-status failures (true) or not (false, the default).
Sourcepub fn max_response_bytes(self, limit: usize) -> Self
pub fn max_response_bytes(self, limit: usize) -> Self
Per-request response body limit, overriding ClientConfig::max_response_bytes.
Sourcepub fn headers_only(self) -> Self
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.
Sourcepub fn cancel(self, token: CancelToken) -> Self
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.