pub trait HttpClient: MaybeSendSync {
// Required method
fn execute(
&self,
request: Request<Bytes>,
idempotency: Idempotency,
) -> MaybeSendBoxFuture<'_, Result<HttpResponse, Error>>;
// Provided method
fn uses_mtls(&self) -> bool { ... }
}Expand description
Executes HTTP requests on behalf of the library, returning a fully-read response.
This trait is dyn-capable: implement it on your client type and the
library consumes it as &dyn HttpClient / Arc<dyn HttpClient>.
§Implementing
Write the method body as Box::pin(async move { ... }). Read the full
response body inside execute, and classify both
request and body-read failures as
ErrorKind::Transport. Mark a
failure retryable only when re-sending the request is known to be
safe: either the request provably never reached the server (a
connection-establishment failure), or the caller declared it
Idempotency::Idempotent and the failure is transient (a timeout, an
interrupted response). With Idempotency::Unknown, the server may
have processed a first attempt that a re-send would replay, so only
never-delivered failures are retryable.
Implementations should bound the size of the response body they buffer.
Every response is read fully into memory (HttpResponse::body), and the
endpoints the library calls — JWKS, token, introspection, discovery — may
be attacker-influenced (for example an authorization server resolved from
user input). An unbounded read lets a malicious or compromised endpoint
exhaust memory with a very large or never-ending body, so enforce a size
limit while reading — aborting before the whole body is buffered — and
reject an oversized body as
ErrorKind::Protocol rather than a
retryable transport failure: re-sending only pulls the same oversized body.
Required Methods§
Sourcefn execute(
&self,
request: Request<Bytes>,
idempotency: Idempotency,
) -> MaybeSendBoxFuture<'_, Result<HttpResponse, Error>>
fn execute( &self, request: Request<Bytes>, idempotency: Idempotency, ) -> MaybeSendBoxFuture<'_, Result<HttpResponse, Error>>
Executes an HTTP request and returns the fully-read response.
§Arguments
request: Thehttp::Requestto be executed. The body is provided asbytes::Bytes.idempotency: Whether the request is known to be safe to re-send, used to classify retryability of transport failures.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T: HttpClient + ?Sized> HttpClient for &T
impl<T: HttpClient + ?Sized> HttpClient for &T
fn execute( &self, request: Request<Bytes>, idempotency: Idempotency, ) -> MaybeSendBoxFuture<'_, Result<HttpResponse, Error>>
fn uses_mtls(&self) -> bool
Source§impl<T: HttpClient + ?Sized> HttpClient for Arc<T>
impl<T: HttpClient + ?Sized> HttpClient for Arc<T>
fn execute( &self, request: Request<Bytes>, idempotency: Idempotency, ) -> MaybeSendBoxFuture<'_, Result<HttpResponse, Error>>
fn uses_mtls(&self) -> bool
Source§impl<T: HttpClient + ?Sized> HttpClient for Box<T>
impl<T: HttpClient + ?Sized> HttpClient for Box<T>
fn execute( &self, request: Request<Bytes>, idempotency: Idempotency, ) -> MaybeSendBoxFuture<'_, Result<HttpResponse, Error>>
fn uses_mtls(&self) -> bool
Implementors§
impl<C: HttpClient> HttpClient for MetricsHttpClient<C>
metrics only.