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 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§
Sourcefn get(&self, url: &str, git_protocol: Option<&str>) -> Result<Vec<u8>>
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.
Sourcefn post(
&self,
url: &str,
content_type: &str,
accept: &str,
body: &[u8],
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>>
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§
Sourcefn git_protocol_header(&self) -> Option<&str>
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.
Sourcefn smart_http_enabled(&self) -> bool
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.
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.