bubble up errors from cloning requests
@@ -35,7 +35,7 @@ where
pub fn execute(&mut self, mut first_request: Request) -> Result<Response> {
// This buffers the body in case we need it again later
// reqwest does *not* do this, it ignores 307/308 with a streaming body
- let mut request = clone_request(&mut first_request);
+ let mut request = clone_request(&mut first_request)?;
let mut response = self.client.execute(first_request)?;
let mut remaining_redirects = self.max_redirects - 1;
@@ -51,7 +51,7 @@ where
if let Some(ref mut callback) = self.callback {
callback(response, &mut next_request)?;
}
- request = clone_request(&mut next_request);
+ request = clone_request(&mut next_request)?;
response = self.client.execute(next_request)?;
}
@@ -59,14 +59,13 @@ where
}
}
-fn clone_request(request: &mut Request) -> Request {
- request
- .body_mut()
- .as_mut()
- .map(|b| b.buffer().expect("unable to buffer request"));
+fn clone_request(request: &mut Request) -> Result<Request> {
+ if let Some(b) = request.body_mut().as_mut() {
+ b.buffer()?;
+ }
// This doesn't copy the contents of the buffer, cloning requests is cheap
// https://docs.rs/bytes/1.0.1/bytes/struct.Bytes.html
- request.try_clone().unwrap() // guaranteed to not fail if body is already buffered
+ Ok(request.try_clone().unwrap()) // guaranteed to not fail if body is already buffered
}
// See https://github.com/seanmonstar/reqwest/blob/bbeb1ede4e8098481c3de6f2cafb8ecca1db4ede/src/async_impl/client.rs#L1500-L1607
