Compare commits
No commits in common. "response-entity" and "main" have entirely different histories.
response-e
...
main
|
@ -24,6 +24,7 @@ from sanic.helpers import (
|
||||||
Default,
|
Default,
|
||||||
_default,
|
_default,
|
||||||
has_message_body,
|
has_message_body,
|
||||||
|
remove_entity_headers,
|
||||||
)
|
)
|
||||||
from sanic.http import Http
|
from sanic.http import Http
|
||||||
|
|
||||||
|
@ -105,6 +106,9 @@ class BaseHTTPResponse:
|
||||||
Returns:
|
Returns:
|
||||||
Iterator[Tuple[bytes, bytes]]: A list of header tuples encoded in bytes for sending
|
Iterator[Tuple[bytes, bytes]]: A list of header tuples encoded in bytes for sending
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
|
# TODO: Make a blacklist set of header names and then filter with that
|
||||||
|
if self.status in (304, 412): # Not Modified, Precondition Failed
|
||||||
|
self.headers = remove_entity_headers(self.headers)
|
||||||
if has_message_body(self.status):
|
if has_message_body(self.status):
|
||||||
self.headers.setdefault("content-type", self.content_type)
|
self.headers.setdefault("content-type", self.content_type)
|
||||||
# Encode headers into bytes
|
# Encode headers into bytes
|
||||||
|
|
|
@ -178,10 +178,6 @@ def json_app(app):
|
||||||
async def unmodified_handler(request: Request):
|
async def unmodified_handler(request: Request):
|
||||||
return json(JSON_DATA, status=304)
|
return json(JSON_DATA, status=304)
|
||||||
|
|
||||||
@app.get("/precondition")
|
|
||||||
async def precondition_handler(request: Request):
|
|
||||||
return json(JSON_DATA, status=412)
|
|
||||||
|
|
||||||
@app.delete("/")
|
@app.delete("/")
|
||||||
async def delete_handler(request: Request):
|
async def delete_handler(request: Request):
|
||||||
return json(None, status=204)
|
return json(None, status=204)
|
||||||
|
@ -197,10 +193,6 @@ def test_json_response(json_app):
|
||||||
assert response.text == json_dumps(JSON_DATA)
|
assert response.text == json_dumps(JSON_DATA)
|
||||||
assert response.json == JSON_DATA
|
assert response.json == JSON_DATA
|
||||||
|
|
||||||
request, response = json_app.test_client.get("/precondition")
|
|
||||||
assert response.status == 412
|
|
||||||
assert response.json == JSON_DATA
|
|
||||||
|
|
||||||
|
|
||||||
def test_no_content(json_app):
|
def test_no_content(json_app):
|
||||||
request, response = json_app.test_client.get("/no-content")
|
request, response = json_app.test_client.get("/no-content")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user