Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient: Send + Sync {
    // Required method
    fn get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        url: &'life1 Url,
    ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn get_accepting<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        url: &'life1 Url,
        media_type: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn allows_plain_http(&self, url: &Url) -> bool { ... }
}
Available on crate feature did-web and (crate features did-jwk or did-key or did-web) only.
Expand description

What DidWeb needs from HTTP: a GET of a URL.

Implement it over the HTTP client of the application so did:web resolution shares its connection pool, proxy and TLS settings. The implementation decides the security policy: ReqwestClient is the one this crate ships.

Every URL a client is given comes from untrusted input (a DID, a credential’s status list reference), so an implementation must refuse what ReqwestClient refuses, or weigh the consequence: plain http, redirects, hosts that resolve to loopback, private, link-local or other non-public addresses, unbounded bodies and unbounded waits.

A client follows no redirect itself: it returns the 3xx response, with its Location in HttpResponse::location. A caller that follows redirects, such as the status list check of the sd-jwt feature, fetches each target with a new call, so that every hop goes through the client’s rules.

Required Methods§

Source

fn get<'life0, 'life1, 'async_trait>( &'life0 self, url: &'life1 Url, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetches url, returning the status and the body of the response.

§Errors

Any failure to get a response: a refused URL, a network or TLS error, a timeout, a body over the client’s limit. An HTTP error status is a response, not an error.

Provided Methods§

Source

fn get_accepting<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, url: &'life1 Url, media_type: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Fetches url asking for a body of media_type, sent as the Accept header.

The default calls get and sends no Accept header; ReqwestClient sends it. Implement it when a server negotiates the content type.

§Errors

As get.

Source

fn allows_plain_http(&self, url: &Url) -> bool

Whether this client may fetch url over plain http.

The fetch helpers built on this trait (the DID configuration of domain_linkage, the presentations of linked_vp, the key sets of JwksResolver and the status list redirects) refuse a URL that is not https before sending a request, unless this returns true for an http URL. The client still decides in get: a true here lets the request reach it, nothing more.

The default is false. ReqwestClient returns true only when built for local development and tests, with the local-network feature.

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 get<'life0, 'life1, 'async_trait>( &'life0 self, url: &'life1 Url, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn get_accepting<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, url: &'life1 Url, media_type: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn allows_plain_http(&self, url: &Url) -> bool

Source§

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

Source§

fn get<'life0, 'life1, 'async_trait>( &'life0 self, url: &'life1 Url, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn get_accepting<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, url: &'life1 Url, media_type: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn allows_plain_http(&self, url: &Url) -> bool

Source§

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

Source§

fn get<'life0, 'life1, 'async_trait>( &'life0 self, url: &'life1 Url, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn get_accepting<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, url: &'life1 Url, media_type: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn allows_plain_http(&self, url: &Url) -> bool

Implementors§