(
send: Callable[[dict[str, Any]], Awaitable[None]],
status_code: int,
payload: dict[str, Any],
)
| 51 | |
| 52 | |
| 53 | async def send_json_response( |
| 54 | send: Callable[[dict[str, Any]], Awaitable[None]], |
| 55 | status_code: int, |
| 56 | payload: dict[str, Any], |
| 57 | ) -> None: |
| 58 | body = json.dumps(payload, separators=(",", ":")).encode("utf-8") |
| 59 | await send( |
| 60 | { |
| 61 | "type": "http.response.start", |
| 62 | "status": status_code, |
| 63 | "headers": [ |
| 64 | (b"content-type", b"application/json"), |
| 65 | (b"content-length", str(len(body)).encode("ascii")), |
| 66 | ], |
| 67 | } |
| 68 | ) |
| 69 | await send({"type": "http.response.body", "body": body}) |