| 98 | raise RuntimeError('Cannot call "send" once a close message has been sent.') |
| 99 | |
| 100 | async def accept( |
| 101 | self, |
| 102 | subprotocol: str | None = None, |
| 103 | headers: Iterable[tuple[bytes, bytes]] | None = None, |
| 104 | ) -> None: |
| 105 | headers = headers or [] |
| 106 | |
| 107 | if self.client_state == WebSocketState.CONNECTING: # pragma: no branch |
| 108 | # If we haven't yet seen the 'connect' message, then wait for it first. |
| 109 | await self.receive() |
| 110 | await self.send({"type": "websocket.accept", "subprotocol": subprotocol, "headers": headers}) |
| 111 | |
| 112 | def _raise_on_disconnect(self, message: Message) -> None: |
| 113 | if message["type"] == "websocket.disconnect": |