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>>;
}
Available on crate features 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§

source

type Headers: BufRead + Unpin

A type providing headers line by line.

source

type ResponseBody: BufRead

A type providing the response.

source

type PostBody: Write

A type allowing to write the content to post.

Required Methods§

source

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.

source

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.

source

fn configure( &mut self, config: &dyn Any ) -> Result<(), Box<dyn Error + Send + Sync + 'static>>

Pass config which can deserialize in the implementation’s configuration, as documented separately.

The caller must know how that config data looks like for the intended implementation.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Http for Curl

Available on crate feature http-client-curl only.