pub struct NativeRequestBuilder { /* private fields */ }Expand description
Builder for a native request addressed by an [http::Uri.
Create one with crate::Client::get_uri or
crate::Client::request_uri. The builder is dispatched through the
native transport, so it applies none of the high-level request policy:
no redirect following, no logical retries, no cookie jar, no
authentication, no response decompression, and no decoded-body limits.
The request is sent exactly once. Self::without_retry and
Self::redirect_policy therefore cannot change the wire behavior;
they exist so the same request-building code can express a
single-attempt contract in every profile.
Implementations§
Source§impl NativeRequestBuilder
impl NativeRequestBuilder
Sourcepub fn header(self, name: &str, value: &str) -> Self
pub fn header(self, name: &str, value: &str) -> Self
Add a single header to the request.
An invalid header name or value is recorded and reported by
Self::build and Self::send.
Sourcepub fn body(self, body: impl Into<RequestBody>) -> Self
pub fn body(self, body: impl Into<RequestBody>) -> Self
Set the request body from any type that converts into
RequestBody.
Sourcepub fn version(self, version: Version) -> Self
pub fn version(self, version: Version) -> Self
Set the HTTP version for this request.
The default is HTTP/1.1. HTTP/2 is selected by protocol negotiation unless the client is built with an explicit version policy.
Sourcepub fn timeout(self, timeout: Timeout) -> Self
pub fn timeout(self, timeout: Timeout) -> Self
Set the timeout for this specific request.
When set, this overrides the client-level timeout on a per-field basis: only fields present here replace the corresponding client-level fields.
Sourcepub fn transport_hints(self, hints: TransportHints) -> Self
pub fn transport_hints(self, hints: TransportHints) -> Self
Set the transport hints for this request.
Transport hints control wire-level behavior (target override, SNI hostname, resolved destination) without affecting logical URL semantics.
Sourcepub fn without_retry(self) -> Self
pub fn without_retry(self) -> Self
Assert that this request must not be retried.
The native transport dispatches exactly once, so this call cannot change the wire behavior: the assertion already holds. It exists so a request built for the high-level API can express the same single-attempt contract in a profile that compiles out the retry engine.
Sourcepub fn redirect_policy(self, policy: RedirectPolicy) -> Self
pub fn redirect_policy(self, policy: RedirectPolicy) -> Self
Attach a redirect policy to this request.
The native transport never follows redirects, so this call cannot change the wire behavior: a 3xx response is returned unchanged. It exists so a request built for the high-level API can express the same “do not follow redirects” contract in a profile that compiles out the redirect loop.
Sourcepub fn build(self) -> Result<Request<RequestBody>>
pub fn build(self) -> Result<Request<RequestBody>>
Build the request without sending it.
§Errors
Returns an error if a previous builder step failed (for example an invalid header).
Sourcepub async fn send(self) -> Result<Response<NativeResponseBody>>
pub async fn send(self) -> Result<Response<NativeResponseBody>>
Build and send the request.
The response is an ordinary http::Response whose body is a
NativeResponseBody. The logical pool lease is held by the
response body until it reaches EOF, errors, or is dropped.
§Errors
Returns an error if the request could not be built or sent.