Skip to main content

ClientExt

Trait ClientExt 

Source
pub trait ClientExt<B>: Client<B>
where B: Body + Send + 'static, <B as Body>::Data: Send, B::Error: Send + Sync + 'static,
{ // Provided methods fn get( &self, url: &Url, headers: impl IntoIterator<Item = (HeaderName, HeaderValue)>, ) -> impl Future<Output = Result<Response<Incoming>, Error>> where B: Default { ... } fn post( &self, url: &Url, headers: impl IntoIterator<Item = (HeaderName, HeaderValue)>, body: B, ) -> impl Future<Output = Result<Response<Incoming>, Error>> { ... } fn get_with_body( &self, url: &Url, headers: impl IntoIterator<Item = (HeaderName, HeaderValue)>, body: B, ) -> impl Future<Output = Result<Response<Incoming>, Error>> { ... } }
Expand description

Extension trait adding specific HTTP method functions (GET, POST, etc.) on top of the base Client trait.

Provided Methods§

Source

fn get( &self, url: &Url, headers: impl IntoIterator<Item = (HeaderName, HeaderValue)>, ) -> impl Future<Output = Result<Response<Incoming>, Error>>
where B: Default,

Sends an HTTP GET request to the connected server and returns the Response.

By definition, HTTP GET requests do not contain a body. Note that the Response body of Incoming means the body must be collected separately from the Response status and headers; this allows the status/headers to be checked before the full body has arrived.

Source

fn post( &self, url: &Url, headers: impl IntoIterator<Item = (HeaderName, HeaderValue)>, body: B, ) -> impl Future<Output = Result<Response<Incoming>, Error>>

Sends an HTTP POST request to the connected server and returns the Response.

Note that the Response body of Incoming means the body must be collected separately from the Response status and headers; this allows the status/headers to be checked before the full body has arrived.

Source

fn get_with_body( &self, url: &Url, headers: impl IntoIterator<Item = (HeaderName, HeaderValue)>, body: B, ) -> impl Future<Output = Result<Response<Incoming>, Error>>

Sends an HTTP GET request carrying a body and returns the Response.

A GET with a request body is unusual, but it is exactly what the upstream Tailnet-Lock sync RPCs (/machine/tka/sync/{offer,send}) do: control routes on the path and reads a JSON body off a GET. This mirrors ClientExt::post but with the GET method, so callers that must match that wire shape don’t have to hand-build a Request (and reach for the private origin-form target helper). Same header defaults as get/post (UA + Host).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, B> ClientExt<B> for T
where T: Client<B>, B: Body + Send + 'static, <B as Body>::Data: Send, B::Error: Send + Sync + 'static,