-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Websocket subprotocol support #874
Comments
hmm.. seems like Also , https://github.com/channelcat/sanic/blob/master/sanic/websocket.py#L48 this piece of code is mainly from the implementation of |
Yes, the support for negotiating a subprotocol is in the What I think makes the most sense here is to implement the negotiation of the subprotocol in @app.websocket('/feed', subprotocols=['foo', 'bar'])
async def feed(request, ws):
if ws.subprotocol:
print('The subprotocol is: ', ws.subprotocol)
while True:
data = 'hello!'
print('Sending: ' + data)
await ws.send(data)
data = await ws.recv()
print('Received: ' + data) |
The websockets library that Sanic utilizes supports passing a list of acceptable websocket subprotocols into their server or client implementations, to be used during the opening handshake ("Sec-WebSocket-Protocol"). Sanic does not support this currently and does not do anything w/ subprotocols in the
websocket_handshake
method. The eventual websocket object that gets passed to the Sanic handler has an "subprotocol" attribute, which would normally be set during the handshake. Currently it is empty. Is there any plan to support subprotocols in the future? Thanks for the excellent framework!The text was updated successfully, but these errors were encountered: