cloudflare / pingora

A library for building fast, reliable and evolvable network services.
Apache License 2.0
20.25k stars 1.1k forks source link

Set `Accept-Ranges: none` header when compressing responses #229

Open palant opened 1 month ago

palant commented 1 month ago

What is the problem your feature solves, or the need it fulfills?

When adjusting response headers, ResponseCompressionCtx will currently remove the Content-Length header as the old header does not apply. A potentially present Accept-Ranges: bytes header is left untouched however, even though ranged requests no longer make sense.

Describe the solution you'd like

Call resp.insert_header(&ACCEPT_RANGES, HeaderValue::from_static("none")) when compressing. This will both overwrite any existing Accept-Ranges header and explicitly indicate to the client that ranged requests are unsupported.

Describe alternatives you've considered

N/A

Additional context

Accept-Ranges header spec

andrewhavck commented 1 week ago

The Accept-Ranges header is removed when compressing a response.

This change was synced internally before 286 was created.

palant commented 1 week ago

@andrewhavck Yes, I got that. I updated #286 to account for the recent changes.

Note that https://github.com/cloudflare/pingora/pull/300/commits/b8ec7aab6fc41bb5d39c5bb1b855219f8f1ac3e7 (correctly) applies to the decompression scenario as well, but it only tests the compression one. My pull request tests both.