no body and content length to 0 when 304 response is returned

This commit is contained in:
Arnulfo Solis 2018-02-02 13:24:51 +01:00
parent 0ab64e9803
commit 7ca3ad5d4c
2 changed files with 19 additions and 1 deletions

View File

@ -198,7 +198,7 @@ class HTTPResponse(BaseHTTPResponse):
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))

View File

@ -67,6 +67,14 @@ def json_app():
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)
@ -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 == ''