Skip to content

Commit

Permalink
Handle ping/pong events in ASGI apps
Browse files Browse the repository at this point in the history
  • Loading branch information
dmontagu committed Feb 21, 2024
1 parent cd0a3dc commit 4958baf
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions httpx_ws/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ async def write(
await self.send({"type": "websocket.receive", "text": event.data})
elif isinstance(event, wsproto.events.BytesMessage):
await self.send({"type": "websocket.receive", "bytes": event.data})
elif isinstance(event, wsproto.events.Ping):
data = self.connection.send(event.response())
await self.write(data)
elif isinstance(event, wsproto.events.Pong):
pass
else:
raise UnhandledWebSocketEvent(event)

Expand Down

0 comments on commit 4958baf

Please sign in to comment.