Mercurial > p > roundup > code
changeset 8019:16cc72cd9c17
fix: Send Vary: Accept-Encoding on any data that could be compressed
This allows upstream caches to return the correct data even when
compression is not in use. It is not sent if the content would never
be compressed. I.E. size < 100 bytes, dynamic compression
disabled, file would not benefit from compression (img/jpeg, img/png).
Fix setVary to add header to vary list only if it's not already there.
Found by redbot.org testing.
References:
https://www.stackpath.com/blog/accept-encoding-vary-important/
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 02 Jun 2024 18:22:53 -0400 |
| parents | 67922fd17454 |
| children | 60c98a8a23bd |
| files | CHANGES.txt roundup/cgi/client.py |
| diffstat | 2 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.txt Sat Jun 01 03:52:02 2024 -0400 +++ b/CHANGES.txt Sun Jun 02 18:22:53 2024 -0400 @@ -161,6 +161,9 @@ rather than reporting a TypeError. (John Rouillard) - Make Last-Modified header use GMT not -0000 timezone. Fix error reported by redbot testing. (John Rouillard) +- Send Vary: Accept-Encoding on any file that could be compressed + even if the file is not encoded/compressed. Found by Redbot + testing. (John Rouillard) Features:
--- a/roundup/cgi/client.py Sat Jun 01 03:52:02 2024 -0400 +++ b/roundup/cgi/client.py Sun Jun 02 18:22:53 2024 -0400 @@ -2355,7 +2355,8 @@ '''Vary header will include the new header. This will append if Vary exists.''' - if ('Vary' in self.additional_headers): + if ('Vary' in self.additional_headers and + header not in self.additional_headers['Vary']): self.additional_headers['Vary'] += ", %s" % header else: self.additional_headers['Vary'] = header @@ -2373,6 +2374,7 @@ # abort if already encoded (e.g. served from # precompressed file or cache on disk) if ('Content-Encoding' in self.additional_headers): + # Vary: 'Accept-Encoding' is set when Content-encoding set return byte_content # abort if file-type already compressed @@ -2381,6 +2383,8 @@ self.precompressed_mime_types): return byte_content + self.setVary('Accept-Encoding') + encoder = None # return same content if unable to compress new_content = byte_content @@ -2419,7 +2423,6 @@ # and add Content-Encoding and Vary header. self.additional_headers['Content-Length'] = str(len(new_content)) self.additional_headers['Content-Encoding'] = encoder - self.setVary('Accept-Encoding') try: current_etag = self.additional_headers['ETag'] except KeyError:
