-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add support for websocket protocol upgrade. #59
Add support for websocket protocol upgrade. #59
Conversation
A ring handler can detect a websocket protocol upgrade request by inspecting the `Connection` and `Upgrade` headers. Then the ring handler may decide to proceed with the upgrade by returning HTTP status 101 (Switching Protocols) with the appropriate websocket upgrade response headers. Then the ring adapter automatically upgrades the HTTP request to a websocket connection. In this case the ring adapter expects the response map to have a `:ws` key containing the websocket handler. The motivation here is to allow clients to connect on the same URI path for regular HTTP calls as well as websockets. E.g. GraphQL clients typically connect on the same URI path (e.g. `/graphql`) for running queries and making subscriptions over websocket. More information on switching protocols at https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/101
I just realized there was already a related open issue: #41 |
Thank you! This is a great step to merge our websocket handler with ring handler. After this patch being merged, I think we can make this a break change to remove legacy websocket handler APIs. |
I admit that I felt tempted to make it compatible with the upcoming Ring 2.0 spec, but it requires listeners to implement the |
@celiocidral We can wait for the final release of Ring 2.0 to support that. Also I am going to support both of Ring's |
Thank you @celiocidral ! I'm going to deprecate |
Sounds great, thanks! Just a quick postmortem comment: for comparing header values, I think String.equalsIgnoreCase might perform a little bit better than |
A ring handler can detect a websocket protocol upgrade request by inspecting the
Connection
andUpgrade
headers. Then the ring handler may decide to proceed with the upgrade by returning HTTP status 101 (Switching Protocols) with the appropriate websocket upgrade response headers. Then the ring adapter automatically upgrades the HTTP request to a websocket connection. In this case the ring adapter expects the response map to have a:ws
key containing the websocket handler.The motivation here is to allow clients to connect on the same URI path for regular HTTP calls as well as websockets. E.g. GraphQL clients typically connect on the same URI path (e.g.
/graphql
) for running queries and making subscriptions over websocket.Two unresolved issues in this PR:
(done).websocket-upgrade-response?
is case-sensitive with regards to reading the response headers.The protocol upgrade support needs to be replicated in(done).proxy-async-handler
I'm planning to fix those two issues in case you approve this draft. There might be other issues that escaped me that you'll probably catch. Please let me know.
More information on switching protocols at https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/101