Skip to content

Commit 612815f

Browse files
handle CLOSE packet in the client (Fixes #100)
1 parent 36a1598 commit 612815f

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

engineio/asyncio_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ async def _receive_packet(self, pkt):
329329
await self._trigger_event('message', pkt.data, run_async=True)
330330
elif pkt.packet_type == packet.PONG:
331331
self.pong_received = True
332+
elif pkt.packet_type == packet.CLOSE:
333+
await self.disconnect(abort=True)
332334
elif pkt.packet_type == packet.NOOP:
333335
pass
334336
else:

engineio/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ def _receive_packet(self, pkt):
418418
self._trigger_event('message', pkt.data, run_async=True)
419419
elif pkt.packet_type == packet.PONG:
420420
self.pong_received = True
421+
elif pkt.packet_type == packet.CLOSE:
422+
self.disconnect(abort=True)
421423
elif pkt.packet_type == packet.NOOP:
422424
pass
423425
else:

tests/asyncio/test_asyncio_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,12 @@ def test_receive_message_packet(self):
610610
c._trigger_event.mock.assert_called_once_with(
611611
'message', {'foo': 'bar'}, run_async=True)
612612

613+
def test_receive_close_packet(self):
614+
c = asyncio_client.AsyncClient()
615+
c.disconnect = AsyncMock()
616+
_run(c._receive_packet(packet.Packet(packet.CLOSE)))
617+
c.disconnect.mock.assert_called_once_with(abort=True)
618+
613619
def test_send_packet_disconnected(self):
614620
c = asyncio_client.AsyncClient()
615621
c.queue = c.create_queue()

tests/common/test_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,12 @@ def test_receive_message_packet(self):
600600
c._trigger_event.assert_called_once_with('message', {'foo': 'bar'},
601601
run_async=True)
602602

603+
def test_receive_close_packet(self):
604+
c = client.Client()
605+
c.disconnect = mock.MagicMock()
606+
c._receive_packet(packet.Packet(packet.CLOSE))
607+
c.disconnect.assert_called_once_with(abort=True)
608+
603609
def test_send_packet_disconnected(self):
604610
c = client.Client()
605611
c.queue = c.create_queue()

0 commit comments

Comments
 (0)