pub struct HttpRequestFactory { /* private fields */ }middleware and _api only.Expand description
Cheaply cloneable request factory used to rebuild a request on demand.
This is the key boundary for middleware support:
- the client captures the request inputs once
- tower layers may clone the factory freely
- retries rebuild the request instead of trying to clone an already-built
reqwest::Request
The Arc is intentional. tower::retry needs to be able to clone the
request handle without forcing the payload itself to be eagerly copied.
The factory handle is cheap to clone; the request is only rebuilt when
build() is actually called.
Implementations§
Source§impl HttpRequestFactory
impl HttpRequestFactory
Sourcepub fn new<F, Fut>(make_request: F) -> Self
Available on non-target_family=wasm only.
pub fn new<F, Fut>(make_request: F) -> Self
target_family=wasm only.Create a replayable request factory from an async request builder.
The closure is stored behind an Arc so this value stays cheap to
clone when it is passed through tower layers.
Sourcepub async fn build(&self) -> Result<Request, OpenAIError>
pub async fn build(&self) -> Result<Request, OpenAIError>
Rebuild the request for the current attempt.
This is what makes retries possible for non-cloneable bodies. The
request is not cloned after construction; instead, the original request
inputs are replayed to produce a fresh reqwest::Request each time.
Trait Implementations§
Source§impl Clone for HttpRequestFactory
impl Clone for HttpRequestFactory
Source§fn clone(&self) -> HttpRequestFactory
fn clone(&self) -> HttpRequestFactory
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 HttpRequestFactory
impl Debug for HttpRequestFactory
Source§impl Policy<HttpRequestFactory, Response, OpenAIError> for SimpleRetryPolicy
impl Policy<HttpRequestFactory, Response, OpenAIError> for SimpleRetryPolicy
Source§type Future = Pin<Box<dyn Future<Output = ()> + Send>>
type Future = Pin<Box<dyn Future<Output = ()> + Send>>
Future type returned by Policy::retry.Source§fn retry(
&mut self,
_req: &mut HttpRequestFactory,
result: &mut Result<Response, OpenAIError>,
) -> Option<Self::Future>
fn retry( &mut self, _req: &mut HttpRequestFactory, result: &mut Result<Response, OpenAIError>, ) -> Option<Self::Future>
Source§fn clone_request(
&mut self,
req: &HttpRequestFactory,
) -> Option<HttpRequestFactory>
fn clone_request( &mut self, req: &HttpRequestFactory, ) -> Option<HttpRequestFactory>
Source§impl<S> Service<HttpRequestFactory> for OpenAIRetry<S>where
S: Service<HttpRequestFactory, Response = Response, Error = OpenAIError> + Clone + Send + 'static,
S::Future: Send + 'static,
Available on non-target_family=wasm only.
impl<S> Service<HttpRequestFactory> for OpenAIRetry<S>where
S: Service<HttpRequestFactory, Response = Response, Error = OpenAIError> + Clone + Send + 'static,
S::Future: Send + 'static,
target_family=wasm only.