Skip to content

Commit

Permalink
Remove Accept-Ranges header when response is compressed
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhavck authored and gumpt committed Jun 21, 2024
1 parent a432c2d commit 35b9f1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .bleep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c54d1250ab2ee9777401b0f8296d30890344cb37
d06210ac024b8f6169ad8ceda71f4915373d2019
5 changes: 5 additions & 0 deletions pingora-core/src/protocols/http/compression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 35b9f1d

Please sign in to comment.