pub struct HttpEngine { /* private fields */ }Expand description
Utility for handling all HTTP operations. The main purpose of this is to de-asyncify HTTP so it can be called in the main TUI thread. All heavy lifting will be pushed to background tasks.
This is safe and cheap to clone because reqwest’s Client type uses Arc
internally. reqwest::Client
Implementations§
Source§impl HttpEngine
impl HttpEngine
Sourcepub fn new(config: &HttpEngineConfig) -> Self
pub fn new(config: &HttpEngineConfig) -> Self
Build a new HTTP engine, which can be used for the entire program life
Sourcepub async fn build(
&self,
seed: RequestSeed,
context: &TemplateContext,
) -> Result<RequestTicket, RequestBuildError>
pub async fn build( &self, seed: RequestSeed, context: &TemplateContext, ) -> Result<RequestTicket, RequestBuildError>
Build a RequestTicket from a RequestSeed. This will render the recipe into a request. The returned ticket can then be launched.
Sourcepub fn rebuild(
&self,
previous_request: &RequestRecord,
) -> Result<RequestTicket, RequestBuildError>
pub fn rebuild( &self, previous_request: &RequestRecord, ) -> Result<RequestTicket, RequestBuildError>
Build a RequestTicket from a past RequestRecord
This will fail only if the body was not saved from the previous request. This happens if:
- Body was larger than HttpEngineConfig::large_body_size
- Body was streamed
Sourcepub async fn build_url(
&self,
seed: RequestSeed,
context: &TemplateContext,
) -> Result<Url, RequestBuildError>
pub async fn build_url( &self, seed: RequestSeed, context: &TemplateContext, ) -> Result<Url, RequestBuildError>
Render just the URL of a request, including query parameters
Sourcepub async fn build_body(
&self,
seed: RequestSeed,
context: &TemplateContext,
) -> Result<Option<Bytes>, RequestBuildError>
pub async fn build_body( &self, seed: RequestSeed, context: &TemplateContext, ) -> Result<Option<Bytes>, RequestBuildError>
Render just the body of a request
Sourcepub async fn build_curl(
&self,
seed: RequestSeed,
context: &TemplateContext,
) -> Result<String, RequestBuildError>
pub async fn build_curl( &self, seed: RequestSeed, context: &TemplateContext, ) -> Result<String, RequestBuildError>
Render a recipe into a cURL command that will execute the request.
Only fails if a header value or body is binary. We can’t represent binary values in the command, so we’d have to push them to a temp file and have curl extract from there. It’s possible, I just haven’t done it yet.
Trait Implementations§
Source§impl Clone for HttpEngine
impl Clone for HttpEngine
Source§fn clone(&self) -> HttpEngine
fn clone(&self) -> HttpEngine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HttpEngine
impl Debug for HttpEngine
Auto Trait Implementations§
impl Freeze for HttpEngine
impl !RefUnwindSafe for HttpEngine
impl Send for HttpEngine
impl Sync for HttpEngine
impl Unpin for HttpEngine
impl UnsafeUnpin for HttpEngine
impl !UnwindSafe for HttpEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more