no body and content length to 0 when 304 response is returned
This commit is contained in:
parent
0ab64e9803
commit
7ca3ad5d4c
|
@ -198,7 +198,7 @@ class HTTPResponse(BaseHTTPResponse):
|
||||||
|
|
||||||
body = b''
|
body = b''
|
||||||
content_length = 0
|
content_length = 0
|
||||||
if self.status is not 204:
|
if self.status is not 204 and self.status != 304:
|
||||||
body = self.body
|
body = self.body
|
||||||
content_length = self.headers.get('Content-Length', len(self.body))
|
content_length = self.headers.get('Content-Length', len(self.body))
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,14 @@ def json_app():
|
||||||
async def no_content_handler(request):
|
async def no_content_handler(request):
|
||||||
return json(JSON_DATA, status=204)
|
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("/")
|
@app.delete("/")
|
||||||
async def delete_handler(request):
|
async def delete_handler(request):
|
||||||
return json(None, status=204)
|
return json(None, status=204)
|
||||||
|
@ -88,6 +96,16 @@ def test_no_content(json_app):
|
||||||
assert response.text == ''
|
assert response.text == ''
|
||||||
assert response.headers['Content-Length'] == '0'
|
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('/')
|
request, response = json_app.test_client.delete('/')
|
||||||
assert response.status == 204
|
assert response.status == 204
|
||||||
assert response.text == ''
|
assert response.text == ''
|
||||||
|
|
Loading…
Reference in New Issue
Block a user