Skip to main content

Http

Struct Http 

Source
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: usize

Implementations§

Source§

impl Http

Source

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.

Source

pub const fn with_retry(self, retry: RetryPolicy) -> Self

Replace the retry policy, which keeps tests from sleeping.

Source

pub const fn with_page_limit(self, page_limit: usize) -> Self

Replace the most pages a listing may span.

Source

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.

Source

fn join(&self, path: &str) -> Result<Url, TransportError>

Join path onto the transport base.

Source

pub async fn json_optional<T: for<'input> Facet<'input>>( &self, method: Method, path: &str, body: Option<&str>, ) -> Result<Option<T>, TransportError>

Like json, but a 404 answers None.

§Errors

Returns any transport, status, or decoding failure except a 404.

Source

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.

Source

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.

Source

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>
where R: for<'input> Facet<'input>, Q: Fn(usize) -> String, E: Fn(R) -> Vec<T>,

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.

Source

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.

Source

pub async fn send_multipart( &self, method: Method, path: &str, form: Form, ) -> Result<String, TransportError>

Send a multipart form. Uploads are not retried.

§Errors

Returns a transport or status failure.

Source

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.

Source

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.

Source

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.

Source

fn request( &self, method: Method, path: &str, ) -> Result<RequestBuilder, TransportError>

An authenticated request to path under the base.

Source

async fn dispatch( request: RequestBuilder, label: &RequestLabel, ) -> Result<Response, TransportError>

Source

async fn text( label: RequestLabel, response: Response, ) -> Result<String, TransportError>

The body of a successful response, or the failure its status maps to.

Source

async fn failure(label: RequestLabel, response: Response) -> TransportError

Trait Implementations§

Source§

impl Clone for Http

Source§

fn clone(&self) -> Http

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Http

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Http

§

impl !UnwindSafe for Http

§

impl Freeze for Http

§

impl Send for Http

§

impl Sync for Http

§

impl Unpin for Http

§

impl UnsafeUnpin for Http

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more