-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 over HTTP2 #1458
Comments
See nodejs/node#23284 (comment). To answer your question, when someone interested in having the feature, will implement it and open a PR. |
@lpinca We rely on ws and want to upgrade our servers to http2. It would be great to have http2 support on ws. |
@ayZagen you are welcome to experiment with it. ws is built on top of the upgrade mechanism for HTTP/1.1 and works with a raw (net.Socket) TCP socket. The way WebSocket works over HTTP/2 is different, the HTTP/2 API is different so it's not trivial to add support for it. Here is a proof of concept: https://github.com/jasnell/http2ws/blob/master/http2ws.js. It might be easier to write a wrapper module with the eventual required additions in ws instead of adding support directly in ws. I am personally not interested in having HTTP/2 support because I think there is no real benefit in using an HTTP/2 stream instead of a raw TCP socket as the transport layer. I understand that in some cases it might be desirable to support HTTP/2 and WebSocket on the same server but I think that in many cases having a separate HTTP/1.1 server only for WebSocket is a good and viable option. |
I'm using node's http2 framework with the Although I would like to see |
@FallingSnow does that do websockets over http2 or is that just falling back to websockets over http1.1? |
@lpinca the big advantage (architecturally) is taking advantage of multiplexing. Right now using websockets sort of requires you to throw away any http-like abstractions (and indeed we often just open a single ws connection to With ws over h2 it can start making sense again for applications / APIs to add per-URL websocket connections for specific change feeds / use cases. (Since all connections are multiplexed through the single h2 tcp socket anyway). The other advantage is faster connection times, since if the page is loaded over h2 then we don't need to do another tcp/TLS handshake to open a websocket. |
WebSocket over HTTP2 has only one advantage that is as you said the use of a single TCP connection when the origin is the same. In all other cases there are only disadvantages especially on the server and with the Node.js HTTP2 implementation. Node.js HTTP2 adds a lot of overhead over a plain See also this discussion dotnet/aspnetcore#7801 and in particular this comment dotnet/aspnetcore#7801 (comment). |
@josephg I believe the connection comes in as an HTTP1.1 request. There is no actual HTTP2 as far as I'm aware. |
Check this out guys: https://nodejs.org/api/http2.html section "The Extended CONNECT Protocol" |
By read all source code of
Because |
Do any browsers support "websocket over http2" now? |
HTTP/2 explicitly disallows WebSocket upgrades. See HTTP/2 Issue #386 for the current status of adding WebSockets semantics to HTTP/2. |
@adelyte-chris RFC 8441 describes how to run the WebSocket protocol over a single stream of an HTTP/2 connection and this is already supported by Node.js. That said, I did not change my mind on this topic. |
@lpinca My mistake, I saw the draft status of the RFC linked in the issue and didn't follow up to see if it had progressed. @masx200 Chromium has support for WebSockets over HTTP/2 behind a command line flag. I found a reference to Firefox support being in development but can't find a tracking issue for it. |
No |
We should make a petition to Google and W3C... This is very concerning for Q3 2020... |
I do not think anybody will do websocket over HTTP2 because they waiting for HTTP3, which it should be done at this time, but they found a problem I think, and it may be will be very late. by the way, it is better to make two software web-server, one for HTTP1.1 or HTTP2, and the second for websocket. |
FYI: Websockets over HTTP/2 will be supported (enabled by default) in Chrome 91 |
Here's a client example using |
Chrome 95 already supports that: https://chromestatus.com/feature/6251293127475200 |
Any plans for supporting it in this library ? |
@szmarczak it looks like you've managed to implement websockets over HTTP2 on both client side and server side using node's http2 module and this ws library. Is that production ready or are there other things that is still needed for full websocket over http2 support? (Like ping/pong... etc). Also why did you do this:
What is the |
Use of ws server-side seems to work fine as-is with a native chromium WebSocket API client. HTTP/1 requests hit the "upgrade" event and HTTP/2 requests hit the "connect" event. Only thing I could imagine adding to ws might be a convenience handleConnect method to the server class, but that saves what - like 15 LOC? Node.js native http2 from "node:http2" for v20.10.0:
Thanks for a great library! |
@brentmjohnson your example only covers the server side and skipping
|
Chrome 121 onwards sends websocket over http/2, so WebSocket over HTTP2 is now kind of mandatory. @brentmjohnson your method works, however the socket is closed by Chrome browser after few seconds and it reconnects the server back again. |
@ackava, i believe most browsers should respect the server's ALPN negotiation, but yeah if your server reports http2 and support for extended connect (re: RFC 8441) i would expect chrome to try websocket over http2. i haven't seen that disconnect issue on chrome 121.0.6167.185 or edge 123.0.2406.0. are you getting anything in the browser console, or perhaps have a proxy between the browser and the server? |
@brentmjohnson Please Disregard my comment, the issue is with engine.io not handling connect event, your workaround does work correctly. I am currently using your work around to connect to socket.io over http1 and proxy the messages (yes overkilling CPU). |
any update? |
Now that node core has added websocket support over http2 nodejs/node#23284, It's nice to know when it will be added to WS?
The text was updated successfully, but these errors were encountered: