From 6cd1f2e06b02d0837f9342c6e8ff63257e0cd23d Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Thu, 13 May 2021 16:56:56 +0800 Subject: [PATCH] reduce handle_response arg --- actix-http/src/h2/dispatcher.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index 367a2bc02..baff20e51 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -104,14 +104,10 @@ where actix_rt::spawn(async move { // resolve service call and send response. let res = match fut.await { - Ok(res) => { - let (res, body) = res.into().replace_body(()); - handle_response(res, body, tx, config).await - } + Ok(res) => handle_response(res.into(), tx, config).await, Err(err) => { - let (res, body) = - Response::from_error(err.into()).replace_body(()); - handle_response(res, body, tx, config).await + let res = Response::from_error(err.into()); + handle_response(res, tx, config).await } }; @@ -141,8 +137,7 @@ enum DispatchError { } async fn handle_response( - res: Response<()>, - body: B, + res: Response, mut tx: SendResponse, config: ServiceConfig, ) -> Result<(), DispatchError> @@ -150,6 +145,8 @@ where B: MessageBody, B::Error: Into, { + let (res, body) = res.replace_body(()); + // prepare response. let mut size = body.size(); let res = prepare_response(config, res.head(), &mut size);