From 35b9f1db00d788c45eefdbe47d3c822c1f65f6d8 Mon Sep 17 00:00:00 2001 From: Andrew Hauck Date: Fri, 7 Jun 2024 17:12:43 -0700 Subject: [PATCH] Remove Accept-Ranges header when response is compressed --- .bleep | 2 +- pingora-core/src/protocols/http/compression/mod.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.bleep b/.bleep index e14ebdd..e1f20d2 100644 --- a/.bleep +++ b/.bleep @@ -1 +1 @@ -c54d1250ab2ee9777401b0f8296d30890344cb37 +d06210ac024b8f6169ad8ceda71f4915373d2019 \ No newline at end of file diff --git a/pingora-core/src/protocols/http/compression/mod.rs b/pingora-core/src/protocols/http/compression/mod.rs index 883c00a..fe1ef63 100644 --- a/pingora-core/src/protocols/http/compression/mod.rs +++ b/pingora-core/src/protocols/http/compression/mod.rs @@ -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"