pub struct HttpClient { /* private fields */ }Expand description
A pooled HTTP client shared by everything that calls out.
Cloning shares the connection pool, which is the point: a per-publisher client would pay a TCP and TLS handshake on every admission.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn with_limits(
&self,
request_timeout: Duration,
maximum_response_bytes: usize,
) -> Self
pub fn with_limits( &self, request_timeout: Duration, maximum_response_bytes: usize, ) -> Self
The same connection pool under different per-request limits.
A deadline and a response ceiling are properties of a request, not of a pool, and admission and hooks want different ones: admission runs inside a publisher’s handshake, while a hook is free to wait. Sharing the client keeps the platform trust store read once and the TLS configuration built once, which is the part worth sharing.
connect_timeout is fixed when the connector is built and so is not
overridable here.
Sourcepub fn with_identity(
config: ClientConfig,
identity: Option<Arc<dyn ResolvesClientCert>>,
roots: Option<Vec<CertificateDer<'static>>>,
) -> Result<Self, OutboundError>
pub fn with_identity( config: ClientConfig, identity: Option<Arc<dyn ResolvesClientCert>>, roots: Option<Vec<CertificateDer<'static>>>, ) -> Result<Self, OutboundError>
Builds a client that also presents an identity, and may pin its trust.
Separate from Self::new rather than an option on it, because the
two answer different questions: new is “who do I trust”, this is
additionally “who am I”. A caller that needs neither should not have to
say so.
identity resolves per handshake, so a rotated certificate is picked up
without rebuilding this client or restarting the process. roots
replaces the platform store when present: a deployment pinning the
authority that signed its own services wants exactly that authority and
not every public one as well.
Sourcepub fn new(config: ClientConfig) -> Result<Self, OutboundError>
pub fn new(config: ClientConfig) -> Result<Self, OutboundError>
Builds a client trusting the platform’s certificate store.
The platform store rather than a bundled root set, so an endpoint behind an internal certificate authority works once that authority is installed the way everything else on the host already expects.
Sourcepub async fn get(&self, endpoint: &Endpoint) -> Result<Response, OutboundError>
pub async fn get(&self, endpoint: &Endpoint) -> Result<Response, OutboundError>
Fetches one URL and reads the whole response.
Used for rotating key sets: the body is JSON, not a form, and there is nothing to POST. Redirects are still not followed — a JWKS URL that 30x’s the origin elsewhere would be a configuration error, not a hop this client should take on its own.
Sourcepub async fn post(
&self,
endpoint: &Endpoint,
content_type: &'static str,
bearer: Option<&BearerToken>,
body: Bytes,
) -> Result<Response, OutboundError>
pub async fn post( &self, endpoint: &Endpoint, content_type: &'static str, bearer: Option<&BearerToken>, body: Bytes, ) -> Result<Response, OutboundError>
Sends one request and reads the whole response.
Sourcepub async fn post_with_headers(
&self,
endpoint: &Endpoint,
content_type: &'static str,
bearer: Option<&BearerToken>,
body: Bytes,
headers: &HeaderMap,
) -> Result<Response, OutboundError>
pub async fn post_with_headers( &self, endpoint: &Endpoint, content_type: &'static str, bearer: Option<&BearerToken>, body: Bytes, headers: &HeaderMap, ) -> Result<Response, OutboundError>
Sends application headers alongside the ordinary content type and credential. The latter remain authoritative even if the supplied map contains them.