Fix JSONResponse default content type (#2737)
This commit is contained in:
parent
6eaab2a7e5
commit
af67801062
|
@ -345,7 +345,7 @@ class JSONResponse(HTTPResponse):
|
||||||
body: Optional[Any] = None,
|
body: Optional[Any] = None,
|
||||||
status: int = 200,
|
status: int = 200,
|
||||||
headers: Optional[Union[Header, Dict[str, str]]] = None,
|
headers: Optional[Union[Header, Dict[str, str]]] = None,
|
||||||
content_type: Optional[str] = None,
|
content_type: str = "application/json",
|
||||||
dumps: Optional[Callable[..., str]] = None,
|
dumps: Optional[Callable[..., str]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
):
|
):
|
||||||
|
|
|
@ -213,3 +213,12 @@ def test_pop_list(json_app: Sanic):
|
||||||
|
|
||||||
_, resp = json_app.test_client.get("/json-pop")
|
_, resp = json_app.test_client.get("/json-pop")
|
||||||
assert resp.body == json_dumps(["b"]).encode()
|
assert resp.body == json_dumps(["b"]).encode()
|
||||||
|
|
||||||
|
|
||||||
|
def test_json_response_class_sets_proper_content_type(json_app: Sanic):
|
||||||
|
@json_app.get("/json-class")
|
||||||
|
async def handler(request: Request):
|
||||||
|
return JSONResponse(JSON_BODY)
|
||||||
|
|
||||||
|
_, resp = json_app.test_client.get("/json-class")
|
||||||
|
assert resp.headers["content-type"] == "application/json"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user