Skip to content
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

http2 websocket #15230

Closed
ronag opened this issue Sep 6, 2017 · 22 comments
Closed

http2 websocket #15230

ronag opened this issue Sep 6, 2017 · 22 comments
Labels
http2 Issues or PRs related to the http2 subsystem.

Comments

@ronag
Copy link
Member

ronag commented Sep 6, 2017

Since http2 does not have the upgrade event maybe the docs should mention how to combine a node http2 server with websockets?

@apapirovski
Copy link
Member

Hi @ronag, you can't use websockets with http2. See https://daniel.haxx.se/blog/2016/06/15/no-websockets-over-http2/ for more info.

@ronag
Copy link
Member Author

ronag commented Sep 6, 2017

@apapirovski: Yes, so somehow I have to start a http1 server on the same port? How does e.g. nginx do it to support both on the same port?

@jasnell
Copy link
Member

jasnell commented Sep 6, 2017

http/2 does have a fallback mechanism that allows http1 and http2 on the same port; for right now the impl in core depends on having a TLS connection and using ALPN to differentiate. See the test case in https://github.com/nodejs/node/blob/master/test/parallel/test-http2-https-fallback.js

It's a bit rough still. We're still working through the details of this particular bit.

@ronag
Copy link
Member Author

ronag commented Sep 6, 2017

@jasnell: Thanks! Where can I follow your progress?

@jasnell
Copy link
Member

jasnell commented Sep 6, 2017

This repo is the best place. It's a bit difficult to follow at times, but if you track the PRs labeled http2 it should be fairly straightforward to follow along.

@ronag
Copy link
Member Author

ronag commented Sep 6, 2017

Would something like this work?

  // Check for websocket path
  if (headers[':path'].startsWith('/deepstream')) {
    const socket = net.connect(ds.port, ds.hostname, () => {
      stream.respond();
      socket.pipe(stream);
      stream.pipe(socket);
    })
  }

@mscdex mscdex added the http2 Issues or PRs related to the http2 subsystem. label Sep 6, 2017
@jasnell
Copy link
Member

jasnell commented Sep 6, 2017

It should, yes.

@jasnell
Copy link
Member

jasnell commented Sep 6, 2017

wait... sorry, I got your threads mixed up... this should work for proxying in general, but not for websockets. There is no way to implement websockets on the same connection as http2

@ronag
Copy link
Member Author

ronag commented Sep 7, 2017

@jasnell: It would be nice to be able to have request listener that only receives the HTTP1 requests with no HTTP2 compat. I am handling HTTP2 in stream handler and the compat request instances are just wasted.

@damianobarbati
Copy link

WOW. That's crazy: so today you have to choose whether use "http2" OR "websockets" with node?

@jasnell
Copy link
Member

jasnell commented May 13, 2018

There is a draft spec for using websockets with http2 but none of the existing implementations support it yet.

@damianobarbati
Copy link

Thanks @jasnell, are you referring to this? https://tools.ietf.org/html/draft-ietf-httpbis-h2-websockets-00
It says:

This Internet-Draft will expire on June 22, 2018.

I'm pretty ignorant here, what's going to happen on June 22 this year?

@jasnell
Copy link
Member

jasnell commented May 13, 2018

All ietf internet draft versions have a six month life span to discourage things from becoming too stale. I would expect an updated draft on or before then

@p3x-robot
Copy link

with spdy it works out of the box with https/2, websocket, it is werid nodejs does not support with http2 with websocket. we use socket.io for everything.

@addaleax
Copy link
Member

@p3x-robot #23284, which was release in v10.12.0 today, allows just that :)

@jasnell
Copy link
Member

jasnell commented Oct 11, 2018

The spec to enable websockets over http2 was just finished by the ietf working group in early September. Support for that just landed in nghttp2 about two weeks ago, and we've landed the basic mechanism in core just this week. I have a working prototype using the ws module. Progress is being made.

@p3x-robot
Copy link

ahh, awesome, i will finally i can delete spdy, testing and thanks you so much for your info!!!!

@damianobarbati
Copy link

@jasnell will websocket over http2 have auto-reconnection logic built-in like SSE? Just wondering, because if they are using the same stream then this should be the case.

@p3x-robot
Copy link

What is SSE here?

@damianobarbati
Copy link

server side events

@p3x-robot
Copy link

I use socket.io but it has reconnection logic not the stream..

@marcoippolito
Copy link

@jasnell James could you provide us some recent material about how to use websockets over http2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http2 Issues or PRs related to the http2 subsystem.
Projects
None yet
Development

No branches or pull requests

8 participants