-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
support custom plugins for HTTP 101 protocol switch #1103
Conversation
cleaned up and published the example websocket plugin, but for now not sure how to identify an unexpected disconnect |
@PixlRainbow, thank you for working on this. It looks very interesting enhancement!
Could Lines 2365 to 2374 in 9e0ff7b
|
Oddly enough, stability issues with high traffic flow only seem to occur in plain http and not in encrypted https. It appears raw TCP sockets have a chance to drop a byte or two every so often, which is enough to break my websocket example implementation. I have noticed another issue that a few servers will simply jump directly to another protocol with HTTP 200 code without going through standard HTTP 101 signalling and negotiation. Web browsers seem to be able to handle these cases fine, but I suspect that is because they have the benefit of having an API dedicated to websocket. May need to add an extra method to allow the user to force a protocol type. |
* now doesn't rely on user defining protocol name in lowercase
handle servers that jump straight to alt protocol without upgrade hint
I don't intend to create an example for the server side, but I added server side support to have feature parity between client and server. |
@yhirose ? |
@PixlRainbow, sorry for the late reply. I'll take a look at it when I have time. |
@PixlRainbow, I just wonder what the comment 'NOT PRODUCTION READY!' in I really appreciate your efforts though, I cannot picture how other users including myself can see real benefit from this pull request. If users want a production level WebSocket solution, I'd recomment uWebSockets which is fully tested for WebSocket support. |
This is a general plugin API. It is not specific to websocket. The websocket code in the example folder is provided merely as an example as to how one could build a plugin to handle alternate protocols. This pull request does not make any websocket-specific changes to httplib itself. The "not production ready" comment is a reference to how the "example code" is not meant for direct implementation in a production environment; in production, a user would have to consider other things like setting up a custom thread pool implementation and designing their own code for reusability. It is similar to how we have an example for SSE in the examples folder that makes use of the content provider/receiver API, but SSE is not directly implemented inside httplib. A real production use case is that a user could use this API to build an adapter between httplib and an existing websocket library to provide the websocket support on the same network port. Or perhaps instead of websocket, they could build their own adapter that allows them to handle http/2.0 requests without requiring us to directly maintain the actual protocol. Or more likely, they can use http 101 as negotiation onto a TCP/TLS protobuf stream. |
Not sure if you have fixed this already, but a few years ago I fixed this problem in a huge open source networking library. |
I do keep polling the |
I'll close it for now since there has been no progress past two years. Please let me know when you come back to this pull request, then I'll reopen it. Thanks. |
Adds a way to add handlers for various protocols and support alternate protocols which use HTTP for initial negotiation.
We will not be responsible for implementing any of those handlers ourselves, but this should at least make it possible for downstream developers to insert their own middleware to partially handle websockets, IRC or other protocols within the same client or server.
I have successfully created an example websocket client plugin with bidirectional support, but have not published it as it seems to have problems with high traffic flow and compatibility with some servers.