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 all commits
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
Binary file added aiohttp/.web_response.py.swo
Binary file not shown.
1 change: 1 addition & 0 deletions aiohttp/web_fileresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def prepare(self, request):
modsince = request.if_modified_since
if modsince is not None and st.st_mtime <= modsince.timestamp():
self.set_status(HTTPNotModified.status_code)
self._length_check = False
Copy link
Member

Choose a reason for hiding this comment

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

This line looks hacky but I could live with it.
Looks like StreamResponse is too coupled with Response class, let's left it for other PR

return (yield from super().prepare(request))

ct, encoding = mimetypes.guess_type(str(filepath))
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.
Binary file added tests/.test_web_sendfile_functional.py.swo
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/test_web_sendfile_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ 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 resp.headers.get('Content-Length') is None
assert b'' == body
resp.close()


Expand Down Expand Up @@ -225,7 +228,10 @@ 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 resp.headers.get('Content-Length') is None
assert b'' == body
resp.close()


Expand Down