-
-
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
Improve websockets integration? #1214
Comments
Possible options:
|
FWIW I've also talked with Tom Christie about websockets integration in uvicorn and I'm thinking about writing a sans-I/O layer to make such integrations easier, see python-websockets/websockets#466 |
Ping @ahopkins - This may help with the other websockets issue. |
@aaugustin I think this is an interesting idea. The handling of websockets in Sanic needs better integration. To the extent that we can work with you and @tomchristie, I'm on board to start those discussions. One thing that I had brought up in the past that probably bears a discussion in this issue is how much websocket support should be bound inside of the Sanic core framework. On the one hand, there is tight bundling as it currently is (you get I think the ideal may be in the middle where websockets receive first class status and are well supported in the API. But, that the dependency is not a requirement (ie |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions. |
Well, I filed it for you rather than for me. It seems valuable to keep track of this even if it takes some years to get done. |
Keeping open since websockets integration is still on the table. |
This issue is now fully superseded by #2000. |
Hello,
I'm the primary author of websockets (the Python library) and I was happy to discover that sanic uses it. Making it possible for third-parties to reuse the protocol was part of my original design. It's the first time I see a project actually taking advantage of this :-)
I see that you're using
WebSocketCommonProtocol
and re-implementing the opening handshake here: https://github.com/channelcat/sanic/blob/e1c90202682d76361c77adb7bb2176730038466a/sanic/websocket.py#L58Unfortunately, you're missing some features I added recently, mainly support for the permessage-deflate extension which compresses messages. It can provide nice performance improvements e.g. when exchanging JSON messages.
Quite obviously you can't take advantage of
WebSocketServerProtocol.handshake
(which handles subprotocol and extensions negotiation) as it currently stands. It starts withpath, request_headers = yield from self.read_http_request()
— which you need to replace with sanic's own HTTP code.Less important potential problems:
websockets
— I already did in previous versions.websockets
is very careful about closing TCP connections correctly. I'm not sure if you need this and take advantage of thisI'd like to support your use case better, by providing a public API that you can hook into.
Are you interested in discussing a better design and coordinating its implementation?
Related issues in
websockets
: python-websockets/websockets#210, python-websockets/websockets#256, python-websockets/websockets#386.The text was updated successfully, but these errors were encountered: