mirror of
https://github.com/TrueLayer/reqwest-middleware.git
synced 2024-12-27 03:16:32 +00:00
Add (send/execute)_with_extensions (#4)
* Add (send/execute)_with_extensions
This commit is contained in:
parent
a92e19d638
commit
9b8cbffb40
2 changed files with 19 additions and 2 deletions
|
@ -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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Added
|
||||||
|
- New methods on `ClientWithExtensions` and `RequestBuilder` for sending requests with initial extensions.
|
||||||
|
|
|
@ -121,9 +121,18 @@ impl ClientWithMiddleware {
|
||||||
/// See
|
/// See
|
||||||
/// [`Client::execute`](https://docs.rs/reqwest/latest/reqwest/struct.Client.html#method.execute)
|
/// [`Client::execute`](https://docs.rs/reqwest/latest/reqwest/struct.Client.html#method.execute)
|
||||||
pub async fn execute(&self, req: Request) -> Result<Response> {
|
pub async fn execute(&self, req: Request) -> Result<Response> {
|
||||||
let next = Next::new(&self.inner, &self.middleware_stack);
|
|
||||||
let mut ext = Extensions::new();
|
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
|
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> {
|
pub fn try_clone(self) -> Option<Self> {
|
||||||
let client = self.client;
|
let client = self.client;
|
||||||
self.inner
|
self.inner
|
||||||
|
|
Loading…
Reference in a new issue