Skip to content
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

tracking/gzip.py was updated - don't gzip if Content-Encoding header present #4

Closed
github-actions bot opened this issue Oct 13, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@github-actions
Copy link

https://raw.githubusercontent.com/encode/starlette/master/starlette/middleware/gzip.py changed:

diff --git a/tracking/gzip.py b/tracking/gzip.py
index 9d69ee7..cbb0f4a 100644
--- a/tracking/gzip.py
+++ b/tracking/gzip.py
@@ -33,6 +33,7 @@ class GZipResponder:
         self.send: Send = unattached_send
         self.initial_message: Message = {}
         self.started = False
+        self.content_encoding_set = False
         self.gzip_buffer = io.BytesIO()
         self.gzip_file = gzip.GzipFile(
             mode="wb", fileobj=self.gzip_buffer, compresslevel=compresslevel
@@ -48,6 +49,13 @@ class GZipResponder:
             # Don't send the initial message until we've determined how to
             # modify the outgoing headers correctly.
             self.initial_message = message
+            headers = Headers(raw=self.initial_message["headers"])
+            self.content_encoding_set = "content-encoding" in headers
+        elif message_type == "http.response.body" and self.content_encoding_set:
+            if not self.started:
+                self.started = True
+                await self.send(self.initial_message)
+            await self.send(message)
         elif message_type == "http.response.body" and not self.started:
             self.started = True
             body = message.get("body", b"")

Close this issue once those changes have been integrated here

github-actions bot pushed a commit that referenced this issue Oct 13, 2022
@simonw simonw added the enhancement New feature or request label Oct 13, 2022
@simonw
Copy link
Owner

simonw commented Oct 13, 2022

@simonw simonw closed this as completed in 616a23e Oct 13, 2022
simonw added a commit that referenced this issue Oct 13, 2022
simonw added a commit that referenced this issue Oct 13, 2022
@simonw
Copy link
Owner

simonw commented Oct 13, 2022

Tweeted about this here: https://twitter.com/simonw/status/1580707619915718656

@simonw simonw changed the title tracking/gzip.py was updated tracking/gzip.py was updated - don't gzip if Content-Encoding header present Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant