mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 22:01:50 +01:00
fix non-empty body of http2 HEAD response (#2920)
Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
parent
b9f0faafde
commit
2f0b8a264a
@ -17,12 +17,16 @@
|
|||||||
- `X_FORWARDED_HOST`
|
- `X_FORWARDED_HOST`
|
||||||
- `X_FORWARDED_PROTO`
|
- `X_FORWARDED_PROTO`
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fix non-empty body of HTTP/2 HEAD responses. [#2920]
|
||||||
|
|
||||||
### Performance
|
### Performance
|
||||||
- Improve overall performance of operations on `Extensions`. [#2890]
|
- Improve overall performance of operations on `Extensions`. [#2890]
|
||||||
|
|
||||||
[#2959]: https://github.com/actix/actix-web/pull/2959
|
[#2959]: https://github.com/actix/actix-web/pull/2959
|
||||||
[#2868]: https://github.com/actix/actix-web/pull/2868
|
[#2868]: https://github.com/actix/actix-web/pull/2868
|
||||||
[#2890]: https://github.com/actix/actix-web/pull/2890
|
[#2890]: https://github.com/actix/actix-web/pull/2890
|
||||||
|
[#2920]: https://github.com/actix/actix-web/pull/2920
|
||||||
[#2957]: https://github.com/actix/actix-web/pull/2957
|
[#2957]: https://github.com/actix/actix-web/pull/2957
|
||||||
[#2955]: https://github.com/actix/actix-web/pull/2955
|
[#2955]: https://github.com/actix/actix-web/pull/2955
|
||||||
[#2956]: https://github.com/actix/actix-web/pull/2956
|
[#2956]: https://github.com/actix/actix-web/pull/2956
|
||||||
|
@ -29,7 +29,7 @@ use crate::{
|
|||||||
HeaderName, HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING, UPGRADE,
|
HeaderName, HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING, UPGRADE,
|
||||||
},
|
},
|
||||||
service::HttpFlow,
|
service::HttpFlow,
|
||||||
Extensions, OnConnectData, Payload, Request, Response, ResponseHead,
|
Extensions, Method, OnConnectData, Payload, Request, Response, ResponseHead,
|
||||||
};
|
};
|
||||||
|
|
||||||
const CHUNK_SIZE: usize = 16_384;
|
const CHUNK_SIZE: usize = 16_384;
|
||||||
@ -118,6 +118,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 +136,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 +207,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,14 +217,14 @@ 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_or_head = 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
|
||||||
.send_response(res, eof)
|
.send_response(res, eof_or_head)
|
||||||
.map_err(DispatchError::SendResponse)?;
|
.map_err(DispatchError::SendResponse)?;
|
||||||
|
|
||||||
if eof {
|
if eof_or_head {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user