We wait for the current flow to be finished before parsing the next message, as we may want to upgrade to WebSocket or plain TCP before that.
(self, event: events.Event)
| 123 | return |
| 124 | |
| 125 | def wait(self, event: events.Event) -> layer.CommandGenerator[None]: |
| 126 | """ |
| 127 | We wait for the current flow to be finished before parsing the next message, |
| 128 | as we may want to upgrade to WebSocket or plain TCP before that. |
| 129 | """ |
| 130 | assert self.stream_id |
| 131 | if isinstance(event, events.DataReceived): |
| 132 | return |
| 133 | elif isinstance(event, events.ConnectionClosed): |
| 134 | # for practical purposes, we assume that a peer which sent at least a FIN |
| 135 | # is not interested in any more data from us, see |
| 136 | # see https://github.com/httpwg/http-core/issues/22 |
| 137 | if event.connection.state is not ConnectionState.CLOSED: |
| 138 | yield commands.CloseConnection(event.connection) |
| 139 | yield ReceiveHttp( |
| 140 | self.ReceiveProtocolError( |
| 141 | self.stream_id, |
| 142 | f"Client disconnected.", |
| 143 | code=ErrorCode.CLIENT_DISCONNECTED, |
| 144 | ) |
| 145 | ) |
| 146 | else: # pragma: no cover |
| 147 | raise AssertionError(f"Unexpected event: {event}") |
| 148 | |
| 149 | def done(self, event: events.ConnectionEvent) -> layer.CommandGenerator[None]: |
| 150 | yield from () # pragma: no cover |