Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient {
    // Required methods
    fn get(
        &self,
        url: &str,
        headers: &[(&str, &str)],
    ) -> Result<HttpResponse, GitError>;
    fn post(
        &self,
        url: &str,
        content_type: &str,
        headers: &[(&str, &str)],
        body: &[u8],
    ) -> Result<HttpResponse, GitError>;

    // Provided method
    fn post_reader(
        &self,
        url: &str,
        content_type: &str,
        headers: &[(&str, &str)],
        body: &mut dyn Read,
    ) -> Result<HttpResponse, GitError> { ... }
}
Expand description

Minimal byte-transport over HTTP(S) used to drive smart-HTTP git transport.

This is the injectable seam through which a host enforces network policy: an implementation owns the entire dial (DNS resolution, connect, TLS) for each url, so a host mirroring attacker-controlled public URLs can supply a client that validates the resolved IP and pins the connection to it, guarding against SSRF. The default fetch/clone path uses UreqHttpClient; see sley_remote::fetch_with_http_client / clone_with_http_client to inject one.

Implementations must surface HTTP error statuses (401/403/404/5xx) as Ok(HttpResponse { status, .. }) so callers can react to them (for example, retrying a 401 with credentials). Only genuine transport failures (DNS/connect/TLS/timeout/protocol) are reported as Err.

Required Methods§

Source

fn get( &self, url: &str, headers: &[(&str, &str)], ) -> Result<HttpResponse, GitError>

Issue a GET for url, sending the additional headers.

Source

fn post( &self, url: &str, content_type: &str, headers: &[(&str, &str)], body: &[u8], ) -> Result<HttpResponse, GitError>

Issue a POST for url with body, sending content_type and the additional headers.

Provided Methods§

Source

fn post_reader( &self, url: &str, content_type: &str, headers: &[(&str, &str)], body: &mut dyn Read, ) -> Result<HttpResponse, GitError>

Issue a POST whose body is streamed from body with chunked transfer-encoding (no Content-Length), so large request bodies never have to be held in memory. The default implementation buffers body and delegates to HttpClient::post; transports that can stream the request (e.g. UreqHttpClient) override this. Callers that need retry-on-auth must be able to regenerate body per attempt, since a reader is consumed once.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl HttpClient for UreqHttpClient

Available on crate feature http-client only.