#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.method: MethodRequest method.
url: StringAbsolute 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: HeaderMapRequest headers. Host is the implementation’s to set, since it
derives from the URL and from any connection reuse the transport
performs.
body: BytesRequest body. Empty for a bodyless method.
timeout: DurationOverall 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: usizeCeiling 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
impl HttpRequest
Sourcepub fn new(method: Method, url: impl Into<String>) -> HttpRequest
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.
Sourcepub fn get(url: impl Into<String>) -> HttpRequest
pub fn get(url: impl Into<String>) -> HttpRequest
A GET for url.
Sourcepub fn header(
self,
name: impl AsRef<str>,
value: impl AsRef<str>,
) -> Result<HttpRequest, HttpTransportError>
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.
Sourcepub fn body(self, body: Bytes) -> HttpRequest
pub fn body(self, body: Bytes) -> HttpRequest
Replace the request body.
Sourcepub fn timeout(self, timeout: Duration) -> HttpRequest
pub fn timeout(self, timeout: Duration) -> HttpRequest
Set the overall deadline.
Sourcepub fn connect_timeout(self, timeout: Duration) -> HttpRequest
pub fn connect_timeout(self, timeout: Duration) -> HttpRequest
Set the connect bound.
Sourcepub fn max_response_bytes(self, max: usize) -> HttpRequest
pub fn max_response_bytes(self, max: usize) -> HttpRequest
Set the response body ceiling.
Trait Implementations§
Source§impl Clone for HttpRequest
impl Clone for HttpRequest
Source§fn clone(&self) -> HttpRequest
fn clone(&self) -> HttpRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for HttpRequest
impl RefUnwindSafe for HttpRequest
impl Send for HttpRequest
impl Sync for HttpRequest
impl Unpin for HttpRequest
impl UnsafeUnpin for HttpRequest
impl UnwindSafe for HttpRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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