You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As discussed on Slack, this would be beneficial as:
1 - RFC 6455 states that WebSocket "is designed to work over HTTP ports 443 and 80 as well as to support HTTP proxies and intermediaries," thus making it compatible with the HTTP protocol. To achieve compatibility, the WebSocket handshake uses the HTTP Upgrade header[1] to change from the HTTP protocol to the WebSocket protocol.
2 - a different port on the same hostname is considered a different origin in CORS policy.
3 - no need to open additional ports through the firewall (especially tricky in corporate environments).
The text was updated successfully, but these errors were encountered:
It is possible to reuse the same socket (i.e. port) for both HTTP traffic and websockets, by running a regular HTTP.serve(...) do http, and inside the body, use HTTP.WebSockets.is_upgrade(http.message) to check that it is an incoming WS connection. If so, call HTTP.WebSockets.upgrade(http) do ws.
Yes @fonsp is right here; there's nothing preventing an HTTP server from serving both HTTP and websocket connections from the same port. On HTTP#master, this is done by calling WebSockets.isupgrade(http.message) and if true, calling WebSockets.upgrade(websocket_handler, http) to initialize the websocket connection.
HTTP.serve doesn't work and HTTP.WebSockets.is_upgrade is renamed in HTTP@1, use HTTP.listen and HTTP.WebSockets.isupgrade(http.message) instead.
I create a pull request to add example code to documentation. #1179
As discussed on Slack, this would be beneficial as:
1 - RFC 6455 states that WebSocket "is designed to work over HTTP ports 443 and 80 as well as to support HTTP proxies and intermediaries," thus making it compatible with the HTTP protocol. To achieve compatibility, the WebSocket handshake uses the HTTP Upgrade header[1] to change from the HTTP protocol to the WebSocket protocol.
2 - a different port on the same hostname is considered a different origin in CORS policy.
3 - no need to open additional ports through the firewall (especially tricky in corporate environments).
The text was updated successfully, but these errors were encountered: