-
-
Notifications
You must be signed in to change notification settings - Fork 971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(gzip): Make sure Vary header is always added if a response can be compressed #2865
Conversation
couldn't we just move the |
Unfortunately, it also needs to be added when the accept-encoding header is not gzip. |
I understand that, that's the goal of this PR. Can't we really avoid this huge diff just to move that up? |
My thinking was I would need to implement a responder for non-gzip encodings, and I also wanted to use the same logic for determining if I shouldn't add the Vary header (body is too small, or streaming response with content-encoding already set). Anyway, I'll try to get it smaller. |
hold, I'm going to review carefully. No need to try anything for now. Thanks for the PR. |
This PR is actually changing the behavior on when we do the compression. It actually implements what is proposed here: #2753 |
Without flushing, the tests would fail. |
That's a change in behavior. I don't think it should flush on every chunk. |
ee2652d
to
f62e152
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. 🙏
Fixes #2863
Summary
Since the presense or absense of the
Accept-Encoding
header can change the response body,Vary
should always be added whether the client requested gzip encoding or not. Otherwise some caching implementations might return a non-compressed response even when a compressed one was requested.This change may seem a bit complex, but it reworks the
GZipMiddleware
to behave the same no matter what the compression is (or lack of). Basic changes include:apply_compression
and don't update thecontent-encoding
orcontent-length
headers if the body didn't change.IdentityResponder
fromGZipResponder
which will be used to respond to non-gzip requests. Itsapply_compression
method will return the body unchanged.Checklist