INNER CODE UNIT · Python
send_with_msgpack
florimondmanca/msgpack-asgi · src/msgpack_asgi/_middleware.py:136
async def send_with_msgpack(self, message: Message) -> None:
if not self._should_encode_from_json_to_msgpack:
await self._send(message)
return
if message["type"] == "http.response.start":
headers = Headers(raw=message["headers"])
if headers["content-type"] != "application/json":
# Client accepts msgpack, but the app did not send JSON data.
# (Note that it may have sent msgpack-encoded data.)
self._should_encode_from_json_to_msgpack = False
await self._send(message)
return
# Don't send the initial message until we've determined how to
# modify the outgoing headers correctly.
self.initial_message = message