Reverted changes related to Accept-Ranges header

This commit is contained in:
Wladimir Palant 2024-06-22 21:47:37 +02:00
parent f647f04bf1
commit 4ea0c3ff10

View file

@ -674,12 +674,8 @@ fn adjust_response_header(resp: &mut ResponseHeader, action: &Action) {
fn set_stream_headers(resp: &mut ResponseHeader) { fn set_stream_headers(resp: &mut ResponseHeader) {
// because the transcoding is streamed, content length is not known ahead // because the transcoding is streamed, content length is not known ahead
resp.remove_header(&CONTENT_LENGTH); resp.remove_header(&CONTENT_LENGTH);
// remove Accept-Ranges header because range requests will no longer work
// Even if upstream supports ranged requests, streamed responses cannot. Replace any resp.remove_header(&ACCEPT_RANGES);
// present Accept-Ranges headers.
// https://www.rfc-editor.org/rfc/rfc9110#field.accept-ranges
resp.insert_header(&ACCEPT_RANGES, HeaderValue::from_static("none"))
.unwrap();
// we stream body now TODO: chunked is for h1 only // we stream body now TODO: chunked is for h1 only
resp.insert_header(&TRANSFER_ENCODING, HeaderValue::from_static("chunked")) resp.insert_header(&TRANSFER_ENCODING, HeaderValue::from_static("chunked"))
@ -733,10 +729,7 @@ fn test_adjust_response_header() {
header.headers.get("transfer-encoding").unwrap().as_bytes(), header.headers.get("transfer-encoding").unwrap().as_bytes(),
b"chunked" b"chunked"
); );
assert_eq!( assert!(header.headers.get("accept-ranges").is_none());
header.headers.get("accept-ranges").unwrap().as_bytes(),
b"none"
);
// compress // compress
let mut header = ResponseHeader::build(200, None).unwrap(); let mut header = ResponseHeader::build(200, None).unwrap();
@ -748,16 +741,9 @@ fn test_adjust_response_header() {
b"gzip" b"gzip"
); );
assert!(header.headers.get("content-length").is_none()); assert!(header.headers.get("content-length").is_none());
assert_eq!( assert!(header.headers.get("accept-ranges").is_none());
header.headers.get("accept-ranges").unwrap().as_bytes(),
b"none"
);
assert_eq!( assert_eq!(
header.headers.get("transfer-encoding").unwrap().as_bytes(), header.headers.get("transfer-encoding").unwrap().as_bytes(),
b"chunked" b"chunked"
); );
assert_eq!(
header.headers.get("accept-ranges").unwrap().as_bytes(),
b"none"
);
} }