-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add websocket subprotocol support #150
Conversation
PR looks good. i don't think anybody uses aiohttp websocket implementation, so i think it's fine if we break api. thanks! |
## Rationale: We have to manually do this currently even while it should be part of the handshake. This leads to ignorance of this feature, and chrome not working due to a missing header when testing only in firefox (which ignores if none of sent subprotocols come back) ## Implementation and usage: I’m adding a kwarg to `do_handshake` which allows the user to specifiy subprotocols his/her client speaks. `do_handshake` returns an additional header with the chosen protocol if the handshake is successful. This doesn’t break the API in any way. If the server speaks any of the supplied subprotocols, the first protocol spoken by both is selected from the the client-supplied list, else the handshake fails. Essentially this means that you order the `protocols` sequence by preference: best protocol first, worst last. ## Open Questions: 1. The agreed-upon protocol is valuable information not only for the Server, but the user: If we speak multiple protocols, we want to know which one the handshake selected. The user has to extract it from the headers, which are simply a sequence and no dict, making this impractical. Should we change the response tuple to include the protocol as fifth mamber? This would break unpacking assignments like this: ```python >>> code, response_headers, parser, writer = do_handshake('get', headers, transport) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: too many values to unpack (expected 4) ``` We could also return something unpackable to 4 elemets that also has a “protocol” field, but that would make the code more complex (tuples are very useful to avoid creating Java-style result-classes). 2. Autobahn|Python forbids duplicate mentions of protocols in the comma-separated list sent by the server. Should we also fail the handshake when this happens or be more lenient?
4ca8df7
to
92ce18b
Compare
old API is ded, long live the new API :) tests pass, and i’m in the contributor list (Phil Schaf is not my real name, therefore the “A.”) |
Looks good for me. Is this ready for merge? |
you tell me. if the tests aren’t sufficient, i can add more, and if they are, well, you see the travis build passed. |
protocol = proto | ||
break | ||
else: | ||
raise errors.HttpBadRequest( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpBadRequest
case is not test-covered as far as I see
Add websocket subprotocol support
Rationale:
We have to manually do this currently even while it should be part of the handshake.
This leads to ignorance of this feature, and chrome not working due to a missing header when testing only in firefox (which ignores if none of sent subprotocols come back)
Implementation and usage:
I’m adding a kwarg to
do_handshake
which allows the user to specifiy subprotocols his/her client speaks.do_handshake
returns an additional header with the chosen protocol if the handshake is successful. This doesn’t break the API in any way.If the server speaks any of the supplied subprotocols, the first protocol spoken by both is selected from the the client-supplied list, else the handshake fails. Essentially this means that you order the
protocols
sequence by preference: best protocol first, worst last.Open Questions:
The agreed-upon protocol is valuable information not only for the Server, but the user: If we speak multiple protocols, we want to know which one the handshake selected. The user has to extract it from the headers, which are simply a sequence and no dict, making this impractical.
Should we change the response tuple to include the protocol as fifth mamber? This would break unpacking assignments like this:
We could also return something unpackable to 4 elemets that also has a “protocol” field, but that would make the code more complex (tuples are very useful to avoid creating Java-style result-classes).
Autobahn|Python forbids duplicate mentions of protocols in the comma-separated list sent by the server. Should we also fail the handshake when this happens or be more lenient?