Skip to main content

HttpRequest

Struct HttpRequest 

Source
#[non_exhaustive]
pub struct HttpRequest { pub method: Method, pub url: String, pub headers: HeaderMap, pub body: Bytes, pub timeout: Duration, pub connect_timeout: Option<Duration>, pub max_response_bytes: usize, }
Expand description

One outbound HTTP request.

Construct with HttpRequest::get / HttpRequest::post / HttpRequest::new and refine with the builder methods. The struct is #[non_exhaustive], so fields can be added without breaking callers; reading the fields from an implementation stays fine.

Bounds are per-request rather than per-transport because the three call sites differ: a JWKS fetch at startup can afford a longer deadline than a token exchange sitting in a request’s critical path.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§method: Method

Request method.

§url: String

Absolute request URL, including scheme.

A String rather than a parsed type so this crate takes no opinion on URL parsing. Implementations parse with whatever their stack already uses, and an unparseable URL surfaces as HttpTransportError::InvalidRequest.

§headers: HeaderMap

Request headers. Host is the implementation’s to set, since it derives from the URL and from any connection reuse the transport performs.

§body: Bytes

Request body. Empty for a bodyless method.

§timeout: Duration

Overall deadline covering connect and I/O. Exceeding it is HttpTransportError::Timeout.

§connect_timeout: Option<Duration>

Bound on connection establishment alone. None leaves it to the implementation.

A hint rather than a guarantee. A transport that pools connections configures the connect bound once for the pool, so a per-request value it cannot apply is ignored — the bundled hyper transport does exactly this. timeout is the bound that always holds, and it covers the connect phase, so ignoring this one shortens no deadline and loses no safety.

Set it when the caller wants connect to fail faster than the overall deadline would allow, and treat honoring it as a bonus.

§max_response_bytes: usize

Ceiling on the buffered response body. Exceeding it is HttpTransportError::ResponseTooLarge rather than a truncated body, because a truncated JWKS document is indistinguishable from a malformed one.

Implementations§

Source§

impl HttpRequest

Source

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

A request with the given method and URL, carrying the default bounds and no headers or body.

Source

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

A GET for url.

Source

pub fn post(url: impl Into<String>, body: Bytes) -> HttpRequest

A POST to url carrying body.

Source

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

Set a header, replacing any existing value for that name.

§Errors

Returns HttpTransportError::InvalidRequest when the name or value is not a legal header. Taking the error here rather than panicking matters because both can come from operator config.

Source

pub fn body(self, body: Bytes) -> HttpRequest

Replace the request body.

Source

pub fn timeout(self, timeout: Duration) -> HttpRequest

Set the overall deadline.

Source

pub fn connect_timeout(self, timeout: Duration) -> HttpRequest

Set the connect bound.

Source

pub fn max_response_bytes(self, max: usize) -> HttpRequest

Set the response body ceiling.

Trait Implementations§

Source§

impl Clone for HttpRequest

Source§

fn clone(&self) -> HttpRequest

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 HttpRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

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> AsDebug for T
where T: Debug,

Source§

fn as_debug(&self) -> &dyn Debug

Returns self as a &dyn Debug trait object.
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, X> CoerceTo<T> for X
where T: CoerceFrom<X> + ?Sized,

Source§

fn coerce_rc_to(self: Rc<X>) -> Rc<T>

Source§

fn coerce_box_to(self: Box<X>) -> Box<T>

Source§

fn coerce_ref_to(&self) -> &T

Source§

fn coerce_mut_to(&mut self) -> &mut T

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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> Same for T

Source§

type Output = T

Should always be Self
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.
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