Skip to main content

HttpRequest

Struct HttpRequest 

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

Immutable snapshot of a single HTTP call produced by crate::HttpRequestBuilder.

Implementations§

Source§

impl HttpRequest

Source

pub fn method(&self) -> &Method

Returns the HTTP verb for this snapshot.

§Returns

Borrowed Method (for example GET or POST).

Source

pub fn set_method(&mut self, method: Method) -> &mut Self

Replaces the HTTP verb.

§Parameters
§Returns

self for method chaining.

Source

pub fn path(&self) -> &str

Returns the path segment or absolute URL string stored on this request.

§Returns

The raw path/URL before query string assembly; may be relative if a base URL is set.

Source

pub fn set_path(&mut self, path: impl Into<String>) -> &mut Self

Replaces the path or absolute URL string.

§Parameters
§Returns

self for method chaining.

Source

pub fn query(&self) -> &[(String, String)]

Returns ordered (name, value) query pairs that will be appended to the resolved URL.

§Returns

Slice view of accumulated query parameters.

Source

pub fn add_query_param( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> &mut Self

Appends a single query pair preserving insertion order.

§Parameters
  • key: Parameter name.
  • value: Parameter value.
§Returns

self for method chaining.

Source

pub fn clear_query_params(&mut self) -> &mut Self

Removes every query pair from this snapshot.

§Returns

self for method chaining.

Source

pub fn headers(&self) -> &HeaderMap

Returns request-local headers layered on top of client defaults and injector output at send time.

§Returns

Borrowed HeaderMap owned by this request only (not merged defaults).

Source

pub fn set_header( &mut self, name: &str, value: &str, ) -> Result<&mut Self, HttpError>

Parses and inserts one header from string name/value pairs.

§Parameters
  • name: Header field name.
  • value: Header field value.
§Returns

Ok(self) on success.

§Errors

Returns HttpError when name or value cannot be converted into valid HTTP tokens.

Source

pub fn set_typed_header( &mut self, name: HeaderName, value: HeaderValue, ) -> &mut Self

Inserts one header using pre-validated HeaderName / HeaderValue types.

§Parameters
  • name: Typed header name.
  • value: Typed header value.
§Returns

self for method chaining.

Source

pub fn remove_header(&mut self, name: &HeaderName) -> &mut Self

Removes all values for a header field by typed name.

§Parameters
  • name: Header name to strip from the request-local map.
§Returns

self for method chaining.

Source

pub fn clear_headers(&mut self) -> &mut Self

Clears all request-local headers (defaults and injectors are unaffected until send).

§Returns

self for method chaining.

Source

pub fn body(&self) -> &HttpRequestBody

Returns the serialized body variant for this snapshot.

§Returns

Borrowed HttpRequestBody.

Source

pub fn set_body(&mut self, body: HttpRequestBody) -> &mut Self

Replaces the entire body payload.

§Parameters
§Returns

self for method chaining.

Source

pub fn request_timeout(&self) -> Option<Duration>

Returns the per-request total timeout, if any.

§Returns

Some(duration) when a request-specific timeout overrides the client default; otherwise None.

Source

pub fn set_request_timeout(&mut self, timeout: Duration) -> &mut Self

Sets a per-request total timeout that overrides the client default for this send.

§Parameters
  • timeout: Upper bound for the entire request lifecycle handled by reqwest.
§Returns

self for method chaining.

Source

pub fn clear_request_timeout(&mut self) -> &mut Self

Drops the per-request timeout so the client-wide default applies again.

§Returns

self for method chaining.

Source

pub fn write_timeout(&self) -> Duration

Returns the write-phase timeout used while sending the request.

Source

pub fn set_write_timeout(&mut self, timeout: Duration) -> &mut Self

Sets the write-phase timeout used while sending the request.

Source

pub fn read_timeout(&self) -> Duration

Returns the read-phase timeout used while reading response body bytes.

Source

pub fn set_read_timeout(&mut self, timeout: Duration) -> &mut Self

Sets the read-phase timeout used while reading response body bytes.

Source

pub fn base_url(&self) -> Option<&Url>

Returns the optional base URL used to resolve relative Self::path values.

§Returns

Some when a base is configured; None when only absolute URLs in path are valid.

Source

pub fn set_base_url(&mut self, base_url: Url) -> &mut Self

Sets the base URL used by Self::resolved_url when path is not absolute.

§Parameters
  • base_url: Root URL to join against relative paths.
§Returns

self for method chaining.

Source

pub fn clear_base_url(&mut self) -> &mut Self

Removes the configured base URL so relative paths can no longer be resolved without resetting it.

§Returns

self for method chaining.

Source

pub fn ipv4_only(&self) -> bool

Returns whether IPv6 literal hosts are rejected after URL resolution.

§Returns

true when a resolved URL whose host is an IPv6 literal must be rejected with HttpError::invalid_url.

Source

pub fn set_ipv4_only(&mut self, enabled: bool) -> &mut Self

Enables or disables IPv6 literal host rejection for resolved URLs.

§Parameters
  • enabled: When true, resolved URLs whose host is an IPv6 literal are errors.
§Returns

self for method chaining.

Source

pub fn cancellation_token(&self) -> Option<&CancellationToken>

Returns the cooperative cancellation handle, if configured.

§Returns

Some token checked before send and during I/O; None when cancellation is not wired.

Source

pub fn set_cancellation_token(&mut self, token: CancellationToken) -> &mut Self

Attaches a CancellationToken that can abort this request cooperatively.

§Parameters
  • token: Shared cancellation source.
§Returns

self for method chaining.

Source

pub fn clear_cancellation_token(&mut self) -> &mut Self

Removes any cancellation token from this snapshot.

§Returns

self for method chaining.

Source

pub fn retry_override(&self) -> &HttpRequestRetryOverride

Returns the per-request retry override applied by the client pipeline.

§Returns

Borrowed HttpRequestRetryOverride.

Source

pub fn set_retry_override( &mut self, retry_override: HttpRequestRetryOverride, ) -> &mut Self

Replaces the retry override for this single request.

§Parameters
  • retry_override: New override policy and knobs.
§Returns

self for method chaining.

Source

pub fn resolved_url_cached(&self) -> Option<Url>

Returns cached resolved URL when available.

Trait Implementations§

Source§

impl Clone for HttpRequest

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HttpRequest

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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