mirror of https://github.com/fafhrd91/actix-web
reduce handle_response arg
This commit is contained in:
parent
924eeda12d
commit
6cd1f2e06b
|
@ -104,14 +104,10 @@ where
|
||||||
actix_rt::spawn(async move {
|
actix_rt::spawn(async move {
|
||||||
// resolve service call and send response.
|
// resolve service call and send response.
|
||||||
let res = match fut.await {
|
let res = match fut.await {
|
||||||
Ok(res) => {
|
Ok(res) => handle_response(res.into(), tx, config).await,
|
||||||
let (res, body) = res.into().replace_body(());
|
|
||||||
handle_response(res, body, tx, config).await
|
|
||||||
}
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let (res, body) =
|
let res = Response::from_error(err.into());
|
||||||
Response::from_error(err.into()).replace_body(());
|
handle_response(res, tx, config).await
|
||||||
handle_response(res, body, tx, config).await
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -141,8 +137,7 @@ enum DispatchError {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_response<B>(
|
async fn handle_response<B>(
|
||||||
res: Response<()>,
|
res: Response<B>,
|
||||||
body: B,
|
|
||||||
mut tx: SendResponse<Bytes>,
|
mut tx: SendResponse<Bytes>,
|
||||||
config: ServiceConfig,
|
config: ServiceConfig,
|
||||||
) -> Result<(), DispatchError>
|
) -> Result<(), DispatchError>
|
||||||
|
@ -150,6 +145,8 @@ where
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
B::Error: Into<Error>,
|
B::Error: Into<Error>,
|
||||||
{
|
{
|
||||||
|
let (res, body) = res.replace_body(());
|
||||||
|
|
||||||
// prepare response.
|
// prepare response.
|
||||||
let mut size = body.size();
|
let mut size = body.size();
|
||||||
let res = prepare_response(config, res.head(), &mut size);
|
let res = prepare_response(config, res.head(), &mut size);
|
||||||
|
|
Loading…
Reference in New Issue