Skip to content

Commit

Permalink
Fix JSONResponse default content type (#2737)
Browse files Browse the repository at this point in the history
  • Loading branch information
prryplatypus committed Apr 10, 2023
1 parent 4ad8168 commit 6b9c1cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sanic/response/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def __init__(
body: Optional[Any] = None,
status: int = 200,
headers: Optional[Union[Header, Dict[str, str]]] = None,
content_type: Optional[str] = None,
content_type: str = "application/json",
dumps: Optional[Callable[..., str]] = None,
**kwargs: Any,
):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_response_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,12 @@ def do_pop(request: Request, response: JSONResponse):

_, resp = json_app.test_client.get("/json-pop")
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"

0 comments on commit 6b9c1cc

Please sign in to comment.