-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow to disable Transfer-Encoding: chunked #1560
Allow to disable Transfer-Encoding: chunked #1560
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1560 +/- ##
==========================================
+ Coverage 91.4% 91.44% +0.03%
==========================================
Files 18 18
Lines 1804 1811 +7
Branches 344 348 +4
==========================================
+ Hits 1649 1656 +7
Misses 131 131
Partials 24 24
Continue to review full report at Codecov.
|
sanic/response.py
Outdated
status=200, | ||
headers=None, | ||
content_type="text/plain", | ||
chunked=None, |
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.
Wouldn't it make more sense in the way you're using this variable to just make it a boolean instead of originally setting it to None
?
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.
I agree.
And, also instead of this:
chunked = self.chunked
self.headers.pop("Content-Length", None)
if chunked is None:
chunked = version != "1.0"
if chunked:
Why not something simpler without any variable assignment?
if self.chunked and version != "1.0"
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.
@ahopkins in general, I think there is a fundamental problem with HTTPResponse
instances: they don't know an exact HTTP version (and some other info about the request) until the response is sent to the client. It forces me to use weird and complicated code like assignments inside the stream
and get_headers
methods instead of __init__
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.
@seemethere @ahopkins ok I tried to simplify it 7d6e60a
sanic/response.py
Outdated
status=200, | ||
headers=None, | ||
content_type="text/plain", | ||
chunked=None, |
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.
I agree.
And, also instead of this:
chunked = self.chunked
self.headers.pop("Content-Length", None)
if chunked is None:
chunked = version != "1.0"
if chunked:
Why not something simpler without any variable assignment?
if self.chunked and version != "1.0"
The
Transfer-Encoding: chunked
is not allowed in some cases:HTTP/1.0
a file streaming, because the
Content-Length
HTTP header is required hereThis PR adds an option to disable it.
Closes #1194
(I hope that
if self.chunked:
expressions don't affect the performance)