pub struct Http {
client: Client,
base: Url,
token: Token,
retry: RetryPolicy,
default_headers: HeaderMap,
page_limit: usize,
}Expand description
Shared HTTP transport for a forge’s REST API.
Debug is derived, which stays safe because Token redacts itself.
Fields§
§client: Client§base: Url§token: Token§retry: RetryPolicy§default_headers: HeaderMap§page_limit: usizeImplementations§
Source§impl Http
impl Http
Sourcepub fn new(
base: Url,
token: Token,
timeout: Duration,
) -> Result<Self, TransportBuildError>
pub fn new( base: Url, token: Token, timeout: Duration, ) -> Result<Self, TransportBuildError>
Build a transport rooted at base. A missing trailing slash is added
so that relative request paths join under the base.
§Errors
Fails when the HTTP stack cannot be built.
Sourcepub const fn with_retry(self, retry: RetryPolicy) -> Self
pub const fn with_retry(self, retry: RetryPolicy) -> Self
Replace the retry policy, which keeps tests from sleeping.
Sourcepub const fn with_page_limit(self, page_limit: usize) -> Self
pub const fn with_page_limit(self, page_limit: usize) -> Self
Replace the most pages a listing may span.
Sourcepub fn with_header(self, name: HeaderName, value: HeaderValue) -> Self
pub fn with_header(self, name: HeaderName, value: HeaderValue) -> Self
Add a header sent on every request, such as an adapter’s required API version header.
Sourcepub async fn json_optional<T: for<'input> Facet<'input>>(
&self,
method: Method,
path: &str,
body: Option<&str>,
) -> Result<Option<T>, TransportError>
pub async fn json_optional<T: for<'input> Facet<'input>>( &self, method: Method, path: &str, body: Option<&str>, ) -> Result<Option<T>, TransportError>
Sourcepub async fn json<T: for<'input> Facet<'input>>(
&self,
method: Method,
path: &str,
body: Option<&str>,
) -> Result<T, TransportError>
pub async fn json<T: for<'input> Facet<'input>>( &self, method: Method, path: &str, body: Option<&str>, ) -> Result<T, TransportError>
Send one request and decode its body as JSON.
§Errors
Returns a transport, status, or decoding failure.
Sourcepub async fn paged<T: for<'input> Facet<'input>, Q: Fn(usize) -> String>(
&self,
page_size: usize,
path: &str,
query_for_page: Q,
) -> Result<Vec<T>, TransportError>
pub async fn paged<T: for<'input> Facet<'input>, Q: Fn(usize) -> String>( &self, page_size: usize, path: &str, query_for_page: Q, ) -> Result<Vec<T>, TransportError>
Read every page of a listing whose pages are plain arrays.
See paged_in.
§Errors
Returns a transport, status, or decoding failure from any page, or
TransportError::TooManyPages.
Sourcepub async fn paged_in<R, T, Q, E>(
&self,
page_size: usize,
path: &str,
query_for_page: Q,
items: E,
) -> Result<Vec<T>, TransportError>
pub async fn paged_in<R, T, Q, E>( &self, page_size: usize, path: &str, query_for_page: Q, items: E, ) -> Result<Vec<T>, TransportError>
Read every page of a paginated listing.
query_for_page builds the query for a one-based page number. It is
appended to path with the right separator.
items takes the entries out of a decoded page, which is how a
response that wraps the list in an object is read. Paging stops once a
page returns fewer than page_size entries or none.
§Errors
Returns a transport, status, or decoding failure from any page, or
TransportError::TooManyPages when the listing is still full after
the page limit.
Sourcepub async fn bytes(
&self,
method: Method,
path: &str,
accept: Option<HeaderValue>,
) -> Result<Vec<u8>, TransportError>
pub async fn bytes( &self, method: Method, path: &str, accept: Option<HeaderValue>, ) -> Result<Vec<u8>, TransportError>
Download a resource’s raw bytes. Binary content is not retried.
accept replaces the default Accept header. Redirects are followed
and reqwest drops the credential when the target is another origin.
§Errors
Returns a transport or status failure.
Sourcepub async fn send_multipart(
&self,
method: Method,
path: &str,
form: Form,
) -> Result<String, TransportError>
pub async fn send_multipart( &self, method: Method, path: &str, form: Form, ) -> Result<String, TransportError>
Sourcepub async fn send_bytes(
&self,
method: Method,
path: &str,
content_type: &str,
bytes: Vec<u8>,
) -> Result<String, TransportError>
pub async fn send_bytes( &self, method: Method, path: &str, content_type: &str, bytes: Vec<u8>, ) -> Result<String, TransportError>
Send a request with a raw byte body and an explicit content type. Uploads are not retried.
§Errors
Returns a transport or status failure.
Sourcepub async fn send(
&self,
method: Method,
path: &str,
body: Option<&str>,
) -> Result<String, TransportError>
pub async fn send( &self, method: Method, path: &str, body: Option<&str>, ) -> Result<String, TransportError>
Send one request, retrying a retryable failure with a doubling delay. A rate limit is retried for every method. A timeout, connection failure, or 5xx is retried only for an idempotent method, because it does not tell whether the forge applied the request.
§Errors
Returns the final transport or status failure once retries, if any, are exhausted.
Sourceasync fn attempt(
&self,
method: Method,
path: &str,
body: Option<&str>,
) -> Result<String, TransportError>
async fn attempt( &self, method: Method, path: &str, body: Option<&str>, ) -> Result<String, TransportError>
One request, with no retry.
Logging records the method, the path, the status, and the duration. It never records a header, so the credential cannot reach a log from here.
Sourcefn request(
&self,
method: Method,
path: &str,
) -> Result<RequestBuilder, TransportError>
fn request( &self, method: Method, path: &str, ) -> Result<RequestBuilder, TransportError>
An authenticated request to path under the base.
async fn dispatch( request: RequestBuilder, label: &RequestLabel, ) -> Result<Response, TransportError>
Sourceasync fn text(
label: RequestLabel,
response: Response,
) -> Result<String, TransportError>
async fn text( label: RequestLabel, response: Response, ) -> Result<String, TransportError>
The body of a successful response, or the failure its status maps to.