Skip to main content

HttpClient

Struct HttpClient 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for HttpClient

Source§

fn clone(&self) -> Self

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 HttpClient

Source§

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

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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