Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient: Send + Sync {
    // Required methods
    fn get(&self, url: &str, git_protocol: Option<&str>) -> Result<Vec<u8>>;
    fn post(
        &self,
        url: &str,
        content_type: &str,
        accept: &str,
        body: &[u8],
        git_protocol: Option<&str>,
    ) -> Result<Vec<u8>>;

    // Provided methods
    fn get_with_final_url(
        &self,
        url: &str,
        git_protocol: Option<&str>,
    ) -> Result<(Vec<u8>, Option<String>)> { ... }
    fn git_protocol_header(&self) -> Option<&str> { ... }
    fn smart_http_enabled(&self) -> bool { ... }
}
Expand description

The minimal HTTP surface the smart-HTTP transport needs.

Implementations legitimately perform real network I/O; the trait makes no assumption about the underlying stack (blocking/async, TLS provider, proxy, cookies), so an embedder can route Git’s HTTP through whatever client it already uses.

The git_protocol argument carries the value of the Git-Protocol request header (e.g. version=2) when the caller wants to negotiate a protocol version; pass it through verbatim. A default Git-Protocol for every request may be supplied via HttpClient::git_protocol_header.

Required Methods§

Source

fn get(&self, url: &str, git_protocol: Option<&str>) -> Result<Vec<u8>>

Issue a GET to url, returning the response body bytes.

§Errors

Returns an error on a transport failure or a non-success HTTP status.

Source

fn post( &self, url: &str, content_type: &str, accept: &str, body: &[u8], git_protocol: Option<&str>, ) -> Result<Vec<u8>>

Issue a POST to url with the given content_type, accept header, and request body, returning the response body bytes.

§Errors

Returns an error on a transport failure or a non-success HTTP status.

Provided Methods§

Source

fn get_with_final_url( &self, url: &str, git_protocol: Option<&str>, ) -> Result<(Vec<u8>, Option<String>)>

Issue a GET to url and return both the response body and the final URL the request resolved to after any HTTP redirects the client followed (None when the client does not track it).

The smart-HTTP transport uses this on the info/refs discovery GET to re-base subsequent git-upload-pack POSTs onto a redirected location (Git’s http.followRedirects): a host that redirects info/refs to a backing host expects the stateless-RPC POSTs there too, and many HTTP clients follow redirects on GET but not on POST. The default implementation calls get and reports no final URL, so existing clients keep working unchanged (without redirect re-basing).

§Errors

Returns an error on a transport failure or a non-success HTTP status.

Source

fn git_protocol_header(&self) -> Option<&str>

The default Git-Protocol request-header value to apply when the caller passes None. Defaults to no header.

Source

fn smart_http_enabled(&self) -> bool

Whether smart-HTTP is enabled (vs. dumb-HTTP fallback). Defaults to true; embedders that honor GIT_SMART_HTTP=0 may return false.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<C: HttpClient> HttpClient for Arc<C>

Forward HttpClient through a shared std::sync::Arc, so one client can back several transports (and be observed by the caller) without moving it.

Source§

fn get(&self, url: &str, git_protocol: Option<&str>) -> Result<Vec<u8>>

Source§

fn post( &self, url: &str, content_type: &str, accept: &str, body: &[u8], git_protocol: Option<&str>, ) -> Result<Vec<u8>>

Source§

fn get_with_final_url( &self, url: &str, git_protocol: Option<&str>, ) -> Result<(Vec<u8>, Option<String>)>

Source§

fn git_protocol_header(&self) -> Option<&str>

Source§

fn smart_http_enabled(&self) -> bool

Implementors§