diff --git a/src/auth.rs b/src/auth.rs index 1b7684fe..1bb20e2e 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -83,7 +83,7 @@ impl<'a> DigestAuthMiddleware<'a> { impl<'a> Middleware for DigestAuthMiddleware<'a> { fn handle(&mut self, mut ctx: Context, mut request: Request) -> Result { - let response = self.next(&mut ctx, clone_request(&mut request)?)?; + let mut response = self.next(&mut ctx, clone_request(&mut request)?)?; match response.headers().get(WWW_AUTHENTICATE) { Some(wwwauth) if response.status() == StatusCode::UNAUTHORIZED => { let mut context = digest_auth::AuthContext::new( @@ -99,7 +99,7 @@ impl<'a> Middleware for DigestAuthMiddleware<'a> { request .headers_mut() .insert(AUTHORIZATION, HeaderValue::from_str(&answer)?); - self.print(&mut ctx, response, &mut request)?; + self.print(&mut ctx, &mut response, &mut request)?; Ok(self.next(&mut ctx, request)?) } _ => Ok(response), diff --git a/src/main.rs b/src/main.rs index fcb4075a..e4930199 100644 --- a/src/main.rs +++ b/src/main.rs @@ -470,13 +470,13 @@ fn run(args: Cli) -> Result { let history_print = args.history_print.unwrap_or(print); let mut client = ClientWithMiddleware::new(&client); if args.all { - client = client.with_printer(|mut prev_response, next_request| { + client = client.with_printer(|prev_response, next_request| { if history_print.response_headers { - printer.print_response_headers(&prev_response)?; + printer.print_response_headers(prev_response)?; } if history_print.response_body { printer.print_response_body( - &mut prev_response, + prev_response, response_charset, response_mime, )?; diff --git a/src/middleware.rs b/src/middleware.rs index 5d8b5d76..8e1f6fc8 100644 --- a/src/middleware.rs +++ b/src/middleware.rs @@ -3,14 +3,14 @@ use reqwest::blocking::{Client, Request, Response}; pub struct Context<'a, 'b> { client: &'a Client, - printer: Option<&'a mut (dyn FnMut(Response, &mut Request) -> Result<()> + 'b)>, + printer: Option<&'a mut (dyn FnMut(&mut Response, &mut Request) -> Result<()> + 'b)>, middlewares: &'a mut [Box], } impl<'a, 'b> Context<'a, 'b> { fn new( client: &'a Client, - printer: Option<&'a mut (dyn FnMut(Response, &mut Request) -> Result<()> + 'b)>, + printer: Option<&'a mut (dyn FnMut(&mut Response, &mut Request) -> Result<()> + 'b)>, middlewares: &'a mut [Box], ) -> Self { Context { @@ -39,7 +39,12 @@ pub trait Middleware { ctx.execute(request) } - fn print(&self, ctx: &mut Context, response: Response, request: &mut Request) -> Result<()> { + fn print( + &self, + ctx: &mut Context, + response: &mut Response, + request: &mut Request, + ) -> Result<()> { if let Some(ref mut printer) = ctx.printer { printer(response, request)?; } @@ -50,7 +55,7 @@ pub trait Middleware { pub struct ClientWithMiddleware<'a, T> where - T: FnMut(Response, &mut Request) -> Result<()>, + T: FnMut(&mut Response, &mut Request) -> Result<()>, { client: &'a Client, printer: Option, @@ -59,7 +64,7 @@ where impl<'a, T> ClientWithMiddleware<'a, T> where - T: FnMut(Response, &mut Request) -> Result<()> + 'a, + T: FnMut(&mut Response, &mut Request) -> Result<()> + 'a, { pub fn new(client: &'a Client) -> Self { ClientWithMiddleware { diff --git a/src/printer.rs b/src/printer.rs index 764c5d0d..98c5d85b 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -435,7 +435,7 @@ impl Printer { let url = response.url().clone(); let content_type = mime.map_or_else(|| get_content_type(response.headers()), ContentType::from); - let encoding = encoding.or_else(|| get_charset(&response)); + let encoding = encoding.or_else(|| get_charset(response)); let compression_type = get_compression_type(response.headers()); let mut body = decompress_stream(response, compression_type); diff --git a/src/redirect.rs b/src/redirect.rs index 70c8dc98..202fef3a 100644 --- a/src/redirect.rs +++ b/src/redirect.rs @@ -36,7 +36,7 @@ impl Middleware for RedirectFollower { self.max_redirects )); } - self.print(&mut ctx, response, &mut next_request)?; + self.print(&mut ctx, &mut response, &mut next_request)?; request = clone_request(&mut next_request)?; response = self.next(&mut ctx, next_request)?; }