diff --git a/CHANGELOG.md b/CHANGELOG.md index d94e3d6..6935d13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/reqwest-middleware/src/client.rs b/reqwest-middleware/src/client.rs index e01e8ca..a629c34 100644 --- a/reqwest-middleware/src/client.rs +++ b/reqwest-middleware/src/client.rs @@ -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 { - 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 { + 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 { + let req = self.inner.build()?; + self.client.execute_with_extensions(req, ext).await + } + pub fn try_clone(self) -> Option { let client = self.client; self.inner