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 post_into_reader(
&self,
url: &str,
content_type: &str,
accept: &str,
body: &[u8],
git_protocol: Option<&str>,
) -> Result<Box<dyn Read + Send>> { ... }
fn post_streaming(
&self,
url: &str,
content_type: &str,
accept: &str,
body: &mut dyn Read,
git_protocol: Option<&str>,
) -> Result<Box<dyn Read + Send>> { ... }
fn get_with_final_url(
&self,
url: &str,
git_protocol: Option<&str>,
) -> Result<(Vec<u8>, Option<String>)> { ... }
fn get_with_final_url_exact(
&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 { ... }
fn reset_auth_after_redirect_rebase(&self) { ... }
fn send(&self, request: &HttpRequest<'_>) -> Result<HttpResponse> { ... }
}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 post_into_reader(
&self,
url: &str,
content_type: &str,
accept: &str,
body: &[u8],
git_protocol: Option<&str>,
) -> Result<Box<dyn Read + Send>>
fn post_into_reader( &self, url: &str, content_type: &str, accept: &str, body: &[u8], git_protocol: Option<&str>, ) -> Result<Box<dyn Read + Send>>
Sourcefn post_streaming(
&self,
url: &str,
content_type: &str,
accept: &str,
body: &mut dyn Read,
git_protocol: Option<&str>,
) -> Result<Box<dyn Read + Send>>
fn post_streaming( &self, url: &str, content_type: &str, accept: &str, body: &mut dyn Read, git_protocol: Option<&str>, ) -> Result<Box<dyn Read + Send>>
Issue a POST whose body is read from body while it is sent, and return
the response body as a readable stream.
Push uses this for request bodies too large to hold in memory (the
packfile), sending them with chunked transfer encoding. The body cannot be
replayed, so the client should not expect an authentication challenge
here: the caller posts a small probe request through
post_into_reader first, which settles
credentials the way Git does before a large push.
The default implementation reads body into memory and calls
post_into_reader. Embedders should override it
so large pushes are not buffered.
§Errors
Returns an error on a transport failure, a failure reading body, or a
non-success HTTP status (including 401, since the body cannot be resent).
Sourcefn get_with_final_url(
&self,
url: &str,
git_protocol: Option<&str>,
) -> Result<(Vec<u8>, Option<String>)>
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.
Sourcefn get_with_final_url_exact(
&self,
url: &str,
git_protocol: Option<&str>,
) -> Result<(Vec<u8>, Option<String>)>
fn get_with_final_url_exact( &self, url: &str, git_protocol: Option<&str>, ) -> Result<(Vec<u8>, Option<String>)>
Like Self::get_with_final_url, but does not merge Self::git_protocol_header
when git_protocol is None (used for forced v0/v1 list_refs).
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.
Sourcefn reset_auth_after_redirect_rebase(&self)
fn reset_auth_after_redirect_rebase(&self)
Drop cached HTTP authorization after an info/refs redirect changed the
effective repository base (Git re-binds credentials via credential_from_url).
Sourcefn send(&self, request: &HttpRequest<'_>) -> Result<HttpResponse>
fn send(&self, request: &HttpRequest<'_>) -> Result<HttpResponse>
Send an arbitrary request and return the response without judging its status.
The resumable transfers (crate::remote::resumable) need methods and headers
the smart-HTTP calls above do not: HEAD, PATCH, Range and the TUS
headers. Unlike Self::get and Self::post, every status comes back
as Ok (a 206, 404 or 409 means something to those callers); only
a transport failure, or an authentication failure the client could not
resolve, is an error. Clients that authenticate should do so here as
they do for Self::get.
The default implementation reports Error::Message saying the client
cannot send such requests, which turns resumable transfers off.
§Errors
A transport or authentication failure.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl HttpClient for Arc<dyn HttpClient>
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 HttpClient for Arc<dyn HttpClient>
Forward HttpClient through a shared std::sync::Arc, so one client can
back several transports (and be observed by the caller) without moving it.