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

Fix FileResponse sending empty chunked body on 304 #2144

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Eduard Iskandarov
Eli Ribble
Elizabeth Leddy
Enrique Saez
Eric Sheng
Erich Healy
Eugene Chernyshov
Eugene Naydenov
Expand Down
3 changes: 2 additions & 1 deletion aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ def _start(self, request,
del headers[CONTENT_LENGTH]
elif self._length_check:
writer.length = self.content_length
if writer.length is None and version >= HttpVersion11:
if (writer.length is None and version >= HttpVersion11 and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fix should be applied to web_fileresponse.py instead of base StreamResponse class.

self._status not in (204, 304)):
writer.enable_chunking()
headers[TRANSFER_ENCODING] = 'chunked'
if CONTENT_LENGTH in headers:
Expand Down
1 change: 1 addition & 0 deletions changes/2143.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix FileResponse sending empty chunked body on 304.
4 changes: 4 additions & 0 deletions tests/test_web_sendfile_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def handler(request):
resp.close()

resp = yield from client.get('/', headers={'If-Modified-Since': lastmod})
body = yield from resp.read()
assert 304 == resp.status
assert b'' == body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @es1024 ,

According to what I read on the RFC:

The Content-Length header should not even be there. Can you add an assert to enforce it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx!

This habit of so many dev to always use .get() 😕 This is so much more readable (and slightly more correct):

assert "Content-Length" not in resp.headers

(Don't bother though, not important)

resp.close()


Expand Down Expand Up @@ -225,7 +227,9 @@ def handler(request):
lastmod = 'Fri, 31 Dec 9999 23:59:59 GMT'

resp = yield from client.get('/', headers={'If-Modified-Since': lastmod})
body = yield from resp.read()
assert 304 == resp.status
assert b'' == body
resp.close()


Expand Down