-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(http-server): add http/2 support based on spdy #2065
Conversation
+1 for adding support for HTTP/2. Personally, I'd prefer to use the built-in HTTP/2 implementation provided by Node.js core, I expect it will have better integration with tooling like traces, monitoring, debugging, etc. and also get security issues fixed more quickly. The built-in @raymondfeng What are your arguments for using a user-land module instead? |
Also note that the built-in |
See also http2's Compatibility API |
@@ -84,14 +91,22 @@ export class HttpServer { | |||
*/ | |||
constructor( | |||
requestListener: RequestListener, | |||
serverOptions?: HttpServerOptions, | |||
serverOptions: HttpServerOptions = {}, | |||
) { | |||
this.requestListener = requestListener; | |||
this.serverOptions = serverOptions; | |||
this._port = serverOptions ? serverOptions.port || 0 : 0; | |||
this._host = serverOptions ? serverOptions.host : undefined; | |||
this._protocol = serverOptions ? serverOptions.protocol || 'http' : 'http'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since serverOptions
are always defined, the checks serverOptions ?:
can be removed now. (This applies to all three lines above.)
@raymondfeng I'd like to better understand the motivations behind this change and the goals you have in mind.
In general, I am very reluctant to force node-spdy dependency on all LB4 users. Also, because HttpServer is exposing the underlying HTTP/1 or HTTP/2 server as a public API, we must carefully consider ramifications of committing to node-spdy server API (as opposed to core From what I was able to find about On the other hand, from what I remember, we use only a small subset of Express functionality. I believe we are relying on two features only:
If that's the case, then I am proposing to rework our internal implementation, drop full Express and replace it with our own composition of lower-level Express components (see https://github.com/pillarjs) from the upcoming version express@5. That way we can stay Express compatible and be able to leverage native Or perhaps even better, replace Express with Fastify which claims compatibility with Express middleware and native HTTP/2 too. Let's discuss! |
Besides the obvious push-based approach for serving files, do we want to support ALPN-based support for falling back to HTTP/1.1? See https://nodejs.org/api/http2.html#http2_alpn_negotiation |
@raymondfeng if your goal is to quickly add an experimental support for HTTP/2 based on https://github.com/spdy-http2/node-spdy, then I am proposing to implement it as a new extension and modify I am thinking about changing the following line: into something like this: this._httpServer = this.httpServerFactory(this.requestHandler, serverOptions); By default, app.bind(RestBindings.SERVER_FACTORY).to((handler, options) => {
return new SpdyServer(
options as spdy.ServerOptions,
handler,
);
});
class SpdyServer implements HttpServer {
// use spdy.createServer() under the hood
// provide HttpServer features like port/host/url, start & stop, etc.
} Just an idea to kickstart the discussion. |
I'm exploring the opportunity to leverage The primary motivtion to use |
Makes sense 👍 I believe HTTP/2 is not required for SSE (server-sent events), SSE works with HTTP/1 too. For example, LB3 (strong-remoting) is using SSE to stream notification about model updates - see http-context.js for the implementation details, the docs and the example client. Also as far as I understand HTTP/2, it does not really provide any benefits for server-sent events compared to HTTP/1. It's always the client who has to initiate the request. The server can speculatively send content for a request that will be requested soon (e.g. css/js assets for a HTML page), but it's still up to the client to request that content. I.e. there is no way for the HTTP/2 server to actively push a new event (a notification) to the client, SSE is using the same never-ending stream as HTTP/1. I am trying to say that missing support for HTTP/2 should not be a blocker for your work on #1884.
I understand that very well after my short research on express+HTTP/2 compatibility on GitHub. What a mess :( I see At the same time, I am perfectly fine to provide HTTP/2 support based on Also by adding an extension point allowing applications/extensions to contribute custom HttpServer implementation, we make LoopBack even more future proof. When HTTP/3 comes closer, we can create another extension to run LoopBack on HTTP/3, even before there is a rock-solid HTTP/3 implementation available for general use. |
It's not a blocker to support SSE with HTTP 1.1. But HTTP/2 + SSE is much more compelling. It's fair to have an extension for http2. I'll see what I can do. |
Superseded by #2078 |
@raymondfeng FYI, a Node.js core maintainer is warning against using node-spdy. https://twitter.com/addaleax/status/1068063898228727814
|
Adds http/2 support using https://github.com/spdy-http2/node-spdy. Even Node.js core now has
http2
support, thespdy
module is express-compatible.Checklist
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated