mirror of https://github.com/fafhrd91/actix-web
fix non-empty body of http2 HEAD response
This commit is contained in:
parent
068909f1b3
commit
8250d331b9
|
@ -1,6 +1,9 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2022-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
### Fixed
|
||||||
|
- Fix non-empty body of http2 HEAD response.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Implement `MessageBody` for `&mut B` where `B: MessageBody + Unpin`. [#2868]
|
- Implement `MessageBody` for `&mut B` where `B: MessageBody + Unpin`. [#2868]
|
||||||
- Implement `MessageBody` for `Pin<B>` where `B::Target: MessageBody`. [#2868]
|
- Implement `MessageBody` for `Pin<B>` where `B::Target: MessageBody`. [#2868]
|
||||||
|
|
|
@ -19,6 +19,7 @@ use h2::{
|
||||||
server::{Connection, SendResponse},
|
server::{Connection, SendResponse},
|
||||||
Ping, PingPong,
|
Ping, PingPong,
|
||||||
};
|
};
|
||||||
|
use http::Method;
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
use tracing::{error, trace, warn};
|
use tracing::{error, trace, warn};
|
||||||
|
|
||||||
|
@ -118,6 +119,7 @@ where
|
||||||
let payload = crate::h2::Payload::new(body);
|
let payload = crate::h2::Payload::new(body);
|
||||||
let pl = Payload::H2 { payload };
|
let pl = Payload::H2 { payload };
|
||||||
let mut req = Request::with_payload(pl);
|
let mut req = Request::with_payload(pl);
|
||||||
|
let head_req = parts.method == Method::HEAD;
|
||||||
|
|
||||||
let head = req.head_mut();
|
let head = req.head_mut();
|
||||||
head.uri = parts.uri;
|
head.uri = parts.uri;
|
||||||
|
@ -135,10 +137,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) => handle_response(res.into(), tx, config).await,
|
Ok(res) => handle_response(res.into(), tx, config, head_req).await,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let res: Response<BoxBody> = err.into();
|
let res: Response<BoxBody> = err.into();
|
||||||
handle_response(res, tx, config).await
|
handle_response(res, tx, config, head_req).await
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -206,6 +208,7 @@ async fn handle_response<B>(
|
||||||
res: Response<B>,
|
res: Response<B>,
|
||||||
mut tx: SendResponse<Bytes>,
|
mut tx: SendResponse<Bytes>,
|
||||||
config: ServiceConfig,
|
config: ServiceConfig,
|
||||||
|
head_req: bool,
|
||||||
) -> Result<(), DispatchError>
|
) -> Result<(), DispatchError>
|
||||||
where
|
where
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
|
@ -215,7 +218,7 @@ where
|
||||||
// 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);
|
||||||
let eof = size.is_eof();
|
let eof = size.is_eof() || head_req;
|
||||||
|
|
||||||
// send response head and return on eof.
|
// send response head and return on eof.
|
||||||
let mut stream = tx
|
let mut stream = tx
|
||||||
|
|
|
@ -126,7 +126,15 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
let (parts, body) = resp.into_parts();
|
let (parts, body) = resp.into_parts();
|
||||||
let payload = if head_req { Payload::None } else { body.into() };
|
let payload = if cfg!(test) {
|
||||||
|
body.into()
|
||||||
|
} else {
|
||||||
|
if head_req {
|
||||||
|
Payload::None
|
||||||
|
} else {
|
||||||
|
body.into()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut head = ResponseHead::new(parts.status);
|
let mut head = ResponseHead::new(parts.status);
|
||||||
head.version = parts.version;
|
head.version = parts.version;
|
||||||
|
|
Loading…
Reference in New Issue