Add (send/execute)_with_extensions (#4)

* Add (send/execute)_with_extensions
reqwest-tracing-0.2
TehPers 2021-09-01 07:08:34 -07:00 committed by GitHub
parent a92e19d638
commit 9b8cbffb40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -5,3 +5,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- New methods on `ClientWithExtensions` and `RequestBuilder` for sending requests with initial extensions.

View File

@ -121,9 +121,18 @@ impl ClientWithMiddleware {
/// See
/// [`Client::execute`](https://docs.rs/reqwest/latest/reqwest/struct.Client.html#method.execute)
pub async fn execute(&self, req: Request) -> Result<Response> {
let next = Next::new(&self.inner, &self.middleware_stack);
let mut ext = Extensions::new();
next.run(req, &mut ext).await
self.execute_with_extensions(req, &mut ext).await
}
/// Executes a request with initial [`Extensions`].
pub async fn execute_with_extensions(
&self,
req: Request,
ext: &mut Extensions,
) -> Result<Response> {
let next = Next::new(&self.inner, &self.middleware_stack);
next.run(req, ext).await
}
}
@ -239,6 +248,12 @@ impl RequestBuilder {
self.client.execute(req).await
}
/// Sends a request with initial [`Extensions`].
pub async fn send_with_extensions(self, ext: &mut Extensions) -> Result<Response> {
let req = self.inner.build()?;
self.client.execute_with_extensions(req, ext).await
}
pub fn try_clone(self) -> Option<Self> {
let client = self.client;
self.inner