Skip to content

Fix _SWITCH_UPGRADE without proposal error message - #168

Merged
sethmlarson merged 1 commit into
python-hyper:masterfrom
karpetrosyan:fix-switch-proposal
Mar 2, 2024
Merged

sethmlarson merged 1 commit into
python-hyper:masterfrom
karpetrosyan:fix-switch-proposal

Conversation

@karpetrosyan

Copy link
Copy Markdown
Contributor

When we try to switch protocols when the client has not requested it, h11 throws a LocalProtocolError.

Here is how h11 do it:

h11/h11/_state.py

Lines 284 to 289 in a2c6894

if server_switch_event not in self.pending_switch_proposals:
raise LocalProtocolError(
"Received server {} event without a pending proposal".format(
server_switch_event
)
)

However, this exception can only be raised when the event is _SWITCH_UPGRADE, because another scenario was already checked here:

h11/h11/_connection.py

Lines 263 to 268 in a2c6894

if type(event) is Response:
if (
_SWITCH_CONNECT in self._cstate.pending_switch_proposals
and 200 <= event.status_code < 300
):
return _SWITCH_CONNECT

In other words, if the server_switch_event is _SWITCH_CONNECT, we always know that such an event is being proposed.

@Kludex Kludex mentioned this pull request Mar 2, 2024
1 task done
@sethmlarson
sethmlarson merged commit 0c08b7c into python-hyper:master Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants