Skip to content

Commit

Permalink
no body and content length to 0 when 304 response is returned
Browse files Browse the repository at this point in the history
  • Loading branch information
arnulfojr committed Feb 2, 2018
1 parent 0ab64e9 commit 7ca3ad5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sanic/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def output(

body = b''
content_length = 0
if self.status is not 204:
if self.status is not 204 and self.status != 304:
body = self.body
content_length = self.headers.get('Content-Length', len(self.body))

Expand Down
18 changes: 18 additions & 0 deletions tests/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ async def test(request):
async def no_content_handler(request):
return json(JSON_DATA, status=204)

@app.get("/no-content/unmodified")
async def no_content_unmodified_handler(request):
return json(None, status=304)

@app.get("/unmodified")
async def unmodified_handler(request):
return json(JSON_DATA, status=304)

@app.delete("/")
async def delete_handler(request):
return json(None, status=204)
Expand All @@ -88,6 +96,16 @@ def test_no_content(json_app):
assert response.text == ''
assert response.headers['Content-Length'] == '0'

request, response = json_app.test_client.get('/no-content/unmodified')
assert response.status == 304
assert response.text == ''
assert response.headers['Content-Length'] == '0'

request, response = json_app.test_client.get('/unmodified')
assert response.status == 304
assert response.text == ''
assert response.headers['Content-Length'] == '0'

request, response = json_app.test_client.delete('/')
assert response.status == 204
assert response.text == ''
Expand Down

0 comments on commit 7ca3ad5

Please sign in to comment.