-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Bypass GZipMiddleware when response includes Content-Encoding
#1901
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,3 +76,27 @@ async def generator(bytes, count): | |
| assert response.text == "x" * 4000 | ||
| assert response.headers["Content-Encoding"] == "gzip" | ||
| assert "Content-Length" not in response.headers | ||
|
|
||
|
|
||
| def test_gzip_ignored_for_responses_with_encoding_set(test_client_factory): | ||
| def homepage(request): | ||
| async def generator(bytes, count): | ||
| for index in range(count): | ||
| yield bytes | ||
|
|
||
| streaming = generator(bytes=b"x" * 400, count=10) | ||
| return StreamingResponse( | ||
| streaming, status_code=200, headers={"Content-Encoding": "br"} | ||
| ) | ||
|
|
||
| app = Starlette( | ||
| routes=[Route("/", endpoint=homepage)], | ||
| middleware=[Middleware(GZipMiddleware)], | ||
| ) | ||
|
|
||
| client = test_client_factory(app) | ||
| response = client.get("/", headers={"accept-encoding": "gzip, br"}) | ||
| assert response.status_code == 200 | ||
| assert response.text == "x" * 4000 | ||
| assert response.headers["Content-Encoding"] == "br" | ||
| assert "Content-Length" not in response.headers | ||
|
Comment on lines
+81
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, this test creates a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah... It was my bad. This test was modified, you can see how it is on master. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh indeed, I found it |
||
Uh oh!
There was an error while loading. Please reload this page.