fix(compress): set Vary: Accept-Encoding on negotiated responses (#5137)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* fix(compress): set Vary: Accept-Encoding on compressed responses The compress middleware negotiates gzip/deflate from the request's Accept-Encoding header but never advertises Vary: Accept-Encoding on the response. A shared cache can then store the compressed body and serve it to a client that did not send a compatible Accept-Encoding, breaking that client. Add Accept-Encoding to the response's Vary header when compressing, appending to any existing Vary value and avoiding duplicates. * fix(compress): set Vary: Accept-Encoding on identity responses too Move the Vary handling ahead of the encoding negotiation so that a response left uncompressed — because Accept-Encoding was absent or offered nothing the middleware supports — is also marked as varying on Accept-Encoding. RFC 9110 lists Accept-Encoding "or lack thereof" as a determining factor, so without this a shared cache can reuse the identity response for a client that does accept gzip. The helper now takes the Context and writes through ctx.header(), which recreates the response when a handler returned a fetch() response. On Node that recreation inherits the immutable header guard from the original response, so the write can still throw; fall back to rebuilding the response around a fresh Headers instance in that case. * refactored * remove the node.js test * ci: apply automated fixes ---------
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: Yusuke Wada <yusuke@kamawada.com>
- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Diff stats
2 files+101 added−0 removed
- tests:+87 added−0 removed
- other:+14 added−0 removed