Skip to main content

RequestBuilder

Struct RequestBuilder 

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

Fluent outbound request builder produced by Client methods.

Implementations§

Source§

impl RequestBuilder

Source

pub const fn without_request_id(self) -> Self

Do not send the current request’s id as x-request-id.

By default, a request sent during an inbound request carries that request’s id (issue #3064). Use this for a host that must not see it.

Source

pub const fn criticality(self, criticality: Criticality) -> Self

Send this criticality in the X-Autumn-Criticality header (issue #3068). Without this call, the client sends the criticality of the inbound request that it serves, if any.

Source

pub fn header(self, name: impl AsRef<str>, value: impl AsRef<str>) -> Self

Append a request header.

Headers named authorization, cookie, or set-cookie are accepted normally but are redacted in tracing events and log output. Invalid header names or values emit a tracing::warn! and are skipped.

Source

pub fn sign_web_bot_auth(self, signer: &WebBotAuthSigner) -> Self

Sign this request with Web Bot Auth (RFC 9421 HTTP Message Signatures), so the receiving site can verify that it comes from this app. Adds Signature-Agent, Signature-Input, and Signature.

The URL must be absolute. Each attempt (a retry, a same-origin redirect) sends a new signature, so a held builder or a late retry never sends an expired one. See crate::aeo::web_bot_auth.

Source

pub fn json<T: Serialize>(self, body: &T) -> Self

Serialise body as JSON and set Content-Type: application/json.

Serialisation errors are captured and returned when send is called rather than being silently discarded.

Source

pub fn text_body(self, body: impl Into<String>) -> Self

Set a plain-text body.

Source

pub fn bytes_body(self, body: impl Into<Bytes>) -> Self

Set a raw byte body, without assuming any content type.

Use this for binary payloads — text_body takes a String and so cannot carry bytes that are not valid UTF-8. Set the content type yourself with header. The Web Push transport uses this for RFC 8291-encrypted bodies.

Source

pub const fn retries(self, max: u32) -> Self

Override the maximum retry count for this request.

This does not enable retries for POST and PATCH. Use retry_non_idempotent for that.

Source

pub const fn retry_non_idempotent(self) -> Self

Retry non-idempotent methods (POST, PATCH) too.

A retried POST can run two times on the server. So for a non-idempotent method, the client sends an Idempotency-Key header with a random value, the same on every attempt. A key you set with header is kept.

Source

pub const fn max_backoff(self, max: Duration) -> Self

Override the cap on the jittered backoff between attempts.

Source

pub const fn max_retry_after(self, max: Duration) -> Self

Override the maximum Retry-After sleep duration for this request.

Source

pub const fn no_retry(self) -> Self

Disable retries for this request.

Source

pub fn no_redirect(self) -> Self

Disable redirect following for this request.

A 3xx response is returned to the caller verbatim (status, headers and body) rather than being followed. Routes the request through the custom one-shot-client send path, which bypasses the process-wide circuit breaker.

Source

pub const fn discard_response_body(self) -> Self

Return the status and headers without reading the response body.

Every other path collects the whole body into memory with no ceiling, which is the right default for an API call whose payload the caller wants. It is the wrong default when the remote host is untrusted and the caller needs only the status: a server that streams indefinitely then costs one unbounded allocation per request until the timeout fires.

Web Push is exactly that shape — the endpoint URL is chosen by the client, and the transport only ever reads the status code — so it sets this. Response::bytes then returns empty; dropping the underlying response closes the connection without draining it.

Source

pub fn follow_redirects<F>(self, max: usize, validator: F) -> Self
where F: Fn(&str) -> bool + Send + Sync + 'static,

Follow up to max redirects, validating each hop before following it.

Before following a 3xx, the Location header is resolved to an absolute URL (relative locations are joined against the current URL) and validator(&absolute_location) is called. If it returns false the request fails with ClientError::RedirectRejected. If the chain would exceed max hops the request fails with ClientError::TooManyRedirects (so max == 0 turns the first 3xx into an error). Routes the request through the custom one-shot-client send path, which bypasses the process-wide circuit breaker.

TOCTOU / rebinding limitation. The validator receives the redirect target as a string (not a resolved IP), and the subsequent connection re-resolves that host via normal DNS. So a validator that inspects IP literals sees only literal hosts, has a connect-time TOCTOU window against a hostname that re-resolves between check and connect, and provides no address pinning. When you need pinned, rebind-safe following that validates every resolved IP and pins the connection per hop, use Client::get_ssrf_safe instead.

Source

pub fn pin_to(self, addr: SocketAddr) -> Self

Pin the connection to addr, skipping DNS resolution.

The original Host header and TLS SNI are preserved; only the address the socket connects to is overridden. This protects against DNS-rebinding / TOCTOU attacks where a hostname re-resolves to a different (private) address between validation and connection.

Requires a domain (hostname) URL host. The pin is enforced via a DNS resolve override, but reqwest/hyper treat an IP-literal URL host as already-resolved and never consult the resolver — so the override is skipped and the socket would connect to the literal in the URL, not the pinned address. A pin_to request whose URL host is an IP literal (IPv4 or IPv6) is therefore rejected at send time with ClientError::PinRequiresDomainHost. Put the desired IP directly in the URL (no pin needed), or use a domain host.

Pinning applies to the initial connection only. Redirects are not followed under pin_to: a 3xx is returned to the caller verbatim (as if no_redirect were set) rather than being auto-followed to a possibly-different host that would be re-resolved via normal DNS, silently escaping the pin. If you need pinned, rebind-safe per-hop following, use Client::get_ssrf_safe instead.

Cannot be combined with follow_redirects. Because the pin only covers the first hop while later hops would re-resolve via DNS, chaining pin_to with follow_redirects (in either order) is rejected at send time with ClientError::IncompatiblePinRedirect rather than silently following a redirect off the pinned address. Use Client::get_ssrf_safe for pinned, per-hop-revalidated redirect following, pin_to alone (which returns the 3xx unfollowed), or follow_redirects without pin_to.

Implemented via a one-shot reqwest::ClientBuilder::resolve(host, addr) scoped to this request. Note that reqwest ignores the port in the resolve override and connects to the port from the request URL, so addr.port() is only honoured when it matches the URL’s port (which it does for addresses obtained by resolving that same URL). Routes the request through the custom one-shot-client send path, which bypasses the process-wide circuit breaker.

Env proxies are bypassed. The pinned client is built with .no_proxy(), so HTTP_PROXY / HTTPS_PROXY / ALL_PROXY are ignored and the socket connects directly to addr. This is required for the pin to hold: reqwest checks proxy interception before the connector where the resolve() override applies, so a configured proxy would otherwise receive the request and re-resolve the host — defeating the pin.

Source

pub fn pin_to_addrs(self, addrs: impl IntoIterator<Item = SocketAddr>) -> Self

Like pin_to, but accepts several addresses for one host.

All addresses go to one request. reqwest tries the next address only if it cannot connect. A loop over pin_to could send a POST body twice.

An empty set makes send fail. It never drops the pin. Every other rule of pin_to applies.

Source

pub const fn ssrf_safe(self) -> Self

Route this request through the SSRF-safe resolve→validate→pin send path documented on Client::get_ssrf_safe, for any HTTP method.

Client::get_ssrf_safe only builds GET requests, but the guarantee it describes — reject a resolved address on the built-in SSRF deny-list, pin the connection to the validated set, re-validate on every redirect hop — is implemented by Self::send purely from this flag and is not GET-specific. Any outbound call whose destination is not a value the app itself chose — a webhook subscriber’s target_url, a user-supplied callback, an OAuth discovery endpoint — needs this on every verb it uses, not only reads. Chain it after Client::post, Client::put, etc.:

ⓘ
client.post(target_url).ssrf_safe().json(&payload).send().await?;

Same incompatibility with pin_to as get_ssrf_safe: this path performs its own per-hop resolve→validate→pin, so chaining an explicit pin is rejected at send time with ClientError::PinNotAllowedWithSsrfSafe.

Source

pub async fn send(self) -> Result<Response, ClientError>

Send the request, applying retries and returning a Response.

§Errors

Returns ClientError::Json if a prior .json() call failed to serialise the body. Returns ClientError::Request for transport errors that exhaust all retry attempts. Returns ClientError::NoMock if the request is made in a test context without a matching mock entry.

§Panics

Contains an internal unreachable!() that guards against a logic error in the retry loop; it cannot be reached in practice.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> AutumnCounterCaches for T
where T: 'static,

Source§

const HAS_COUNTER_CACHES: bool = false

Whether this model has any counter cache at all. Read more
Source§

fn counter_caches() -> &'static [CounterCacheSpec<Self>]

The model’s counter-cache specs, in declaration order.
Source§

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

Source§

fn dependents() -> &'static [RuntimeDependentSpec]

The model’s dependent-cascade specs, in declaration order. Defaults to none; #[model] overrides via an inherent shadow when dependents exist.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

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

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

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

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

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

Source§

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

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

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

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

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

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

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

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

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> Instrument for T

Source§

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

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

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> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, Conn> RunQueryDsl<Conn> for T

Source§

fn execute<'conn, 'query>( self, conn: &'conn mut Conn, ) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
where Conn: AsyncConnectionCore + Send, Self: ExecuteDsl<Conn> + 'query,

Executes the given command, returning the number of rows affected. Read more
Source§

fn load<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
where U: Send, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Executes the given query, returning a Vec with the returned rows. Read more
Source§

fn load_stream<'conn, 'query, U>( self, conn: &'conn mut Conn, ) -> Self::LoadFuture<'conn>
where Conn: AsyncConnectionCore, U: 'conn, Self: LoadQuery<'query, Conn, U> + 'query,

Executes the given query, returning a [Stream] with the returned rows. Read more
Source§

fn get_result<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
where U: Send + 'conn, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Runs the command, and returns the affected row. Read more
Source§

fn get_results<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
where U: Send, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Runs the command, returning an Vec with the affected rows. Read more
Source§

fn first<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<<Self::Output as LoadQuery<'query, Conn, U>>::LoadFuture<'conn>, LoadNext<Pin<Box<<Self::Output as LoadQuery<'query, Conn, U>>::Stream<'conn>>>>>
where U: Send + 'conn, Conn: AsyncConnectionCore, Self: LimitDsl, Self::Output: LoadQuery<'query, Conn, U> + Send + 'query,

Attempts to load a single record. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scoped for T
where T: Send + Sync + 'static,

Source§

fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>

Open a deferred ScopeQuery for this type. Resolves the registered scope at .load() time, not here.
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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