pub trait Http {
type Headers: BufRead + Unpin;
type ResponseBody: BufRead;
type PostBody: Write;
// Required methods
fn get(
&mut self,
url: &str,
base_url: &str,
headers: impl IntoIterator<Item = impl AsRef<str>>,
) -> Result<GetResponse<Self::Headers, Self::ResponseBody>, Error>;
fn post(
&mut self,
url: &str,
base_url: &str,
headers: impl IntoIterator<Item = impl AsRef<str>>,
body: PostBodyDataKind,
) -> Result<PostResponse<Self::Headers, Self::ResponseBody, Self::PostBody>, Error>;
fn configure(
&mut self,
config: &dyn Any,
) -> Result<(), Box<dyn Error + Send + Sync + 'static>>;
}
blocking-client
and http-client
only.Expand description
A trait to abstract the HTTP operations needed to power all git interactions: read via GET and write via POST.
Note that 401 must be turned into std::io::Error(PermissionDenied)
, and other non-success http statuses must be transformed
into std::io::Error(Other)
Required Associated Types§
sourcetype ResponseBody: BufRead
type ResponseBody: BufRead
A type providing the response.
Required Methods§
sourcefn get(
&mut self,
url: &str,
base_url: &str,
headers: impl IntoIterator<Item = impl AsRef<str>>,
) -> Result<GetResponse<Self::Headers, Self::ResponseBody>, Error>
fn get( &mut self, url: &str, base_url: &str, headers: impl IntoIterator<Item = impl AsRef<str>>, ) -> Result<GetResponse<Self::Headers, Self::ResponseBody>, Error>
Initiate a GET
request to url
provided the given headers
, where base_url
is so that base_url + tail == url
.
The base_url
helps to validate redirects and to swap it with the effective base after a redirect.
The headers
are provided verbatim and include both the key as well as the value.
sourcefn post(
&mut self,
url: &str,
base_url: &str,
headers: impl IntoIterator<Item = impl AsRef<str>>,
body: PostBodyDataKind,
) -> Result<PostResponse<Self::Headers, Self::ResponseBody, Self::PostBody>, Error>
fn post( &mut self, url: &str, base_url: &str, headers: impl IntoIterator<Item = impl AsRef<str>>, body: PostBodyDataKind, ) -> Result<PostResponse<Self::Headers, Self::ResponseBody, Self::PostBody>, Error>
Initiate a POST
request to url
providing with the given headers
, where base_url
is so that base_url + tail == url
.
The base_url
helps to validate redirects and to swap it with the effective base after a redirect.
The headers
are provided verbatim and include both the key as well as the value.
Note that the PostResponse
contains the post_body
field which implements std::io::Write
and is expected to receive the body to post to the server. It must be dropped before reading the response
to prevent deadlocks.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.