Remove Accept-Ranges header when response is compressed

This commit is contained in:
Andrew Hauck 2024-06-07 17:12:43 -07:00 committed by Matthew (mbg)
parent a432c2da9b
commit 35b9f1db00
2 changed files with 6 additions and 1 deletions

2
.bleep
View file

@ -1 +1 @@
c54d1250ab2ee9777401b0f8296d30890344cb37
d06210ac024b8f6169ad8ceda71f4915373d2019

View file

@ -19,6 +19,7 @@
use super::HttpTask;
use bytes::Bytes;
use http::header::ACCEPT_RANGES;
use log::warn;
use pingora_error::{ErrorType, Result};
use pingora_http::{RequestHeader, ResponseHeader};
@ -553,6 +554,8 @@ fn adjust_response_header(resp: &mut ResponseHeader, action: &Action) {
fn set_stream_headers(resp: &mut ResponseHeader) {
// because the transcoding is streamed, content length is not known ahead
resp.remove_header(&CONTENT_LENGTH);
// remove Accept-Ranges header because range requests will no longer work
resp.remove_header(&ACCEPT_RANGES);
// we stream body now TODO: chunked is for h1 only
resp.insert_header(&TRANSFER_ENCODING, HeaderValue::from_static("chunked"))
.unwrap();
@ -607,12 +610,14 @@ fn test_adjust_response_header() {
// compress
let mut header = ResponseHeader::build(200, None).unwrap();
header.insert_header("content-length", "20").unwrap();
header.insert_header("accept-ranges", "bytes").unwrap();
adjust_response_header(&mut header, &Compress(Gzip));
assert_eq!(
header.headers.get("content-encoding").unwrap().as_bytes(),
b"gzip"
);
assert!(header.headers.get("content-length").is_none());
assert!(header.headers.get("accept-ranges").is_none());
assert_eq!(
header.headers.get("transfer-encoding").unwrap().as_bytes(),
b"chunked"