Skip to main content

HttpClient

Trait HttpClient 

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

Source

fn execute( &self, request: Request<Bytes>, idempotency: Idempotency, ) -> MaybeSendBoxFuture<'_, Result<HttpResponse, Error>>

Executes an HTTP request and returns the fully-read response.

§Arguments
  • request: The http::Request to be executed. The body is provided as bytes::Bytes.
  • idempotency: Whether the request is known to be safe to re-send, used to classify retryability of transport failures.

Provided Methods§

Source

fn uses_mtls(&self) -> bool

Indicates whether this client uses mTLS for authentication.

If true, grants should prefer to use mTLS endpoint aliases (RFC 8705 §5) when making requests to the authorization server.

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

Source§

fn execute( &self, request: Request<Bytes>, idempotency: Idempotency, ) -> MaybeSendBoxFuture<'_, Result<HttpResponse, Error>>

Source§

fn uses_mtls(&self) -> bool

Source§

impl<T: HttpClient + ?Sized> HttpClient for Arc<T>

Source§

fn execute( &self, request: Request<Bytes>, idempotency: Idempotency, ) -> MaybeSendBoxFuture<'_, Result<HttpResponse, Error>>

Source§

fn uses_mtls(&self) -> bool

Source§

impl<T: HttpClient + ?Sized> HttpClient for Box<T>

Source§

fn execute( &self, request: Request<Bytes>, idempotency: Idempotency, ) -> MaybeSendBoxFuture<'_, Result<HttpResponse, Error>>

Source§

fn uses_mtls(&self) -> bool

Implementors§

Source§

impl<C: HttpClient> HttpClient for MetricsHttpClient<C>

Available on crate feature metrics only.