MatthewWid / better-sse

⬆ Dead simple, dependency-less, spec-compliant server-sent events implementation for Node, written in TypeScript.
MIT License
485 stars 14 forks source link

HTTP/2 Support #40

Closed MatthewWid closed 2 years ago

MatthewWid commented 2 years ago

Resolves #37.

This PR adds quasi-HTTP/2 support by updating the Session class to alternatively accept the Node HTTP/2 compatibility API Http2ServerRequest and Http2ServerResponse interfaces, adjusting the response headers appropriately.

Note that this is only adding support for the compatibility version of the Node HTTP/2 implementation, not the direct core API, as that would be a more challenging task most likely requiring breaking changes to the package API. Support for the core API is not currently planned.

In addition, this PR also updates all development dependencies to their latest non-breaking versions.

strarsis commented 2 years ago

Great! When already a HTTPS/HTTP2 reverse proxy like Traefik is being used, will using the HTTP2 variant of this package improve performance?

MatthewWid commented 2 years ago

@strarsis This change is more an improvement that makes it possible to use Better SSE while also using HTTP/2 directly from your Node server (as long as you are okay using the compatibility version of the HTTP/2 API).

If you are already using HTTP/2 in your reverse proxy you shouldn't see a performance difference.

If you are looking for perf improvements, though, I'd say keep an eye on #35 which from my rudimentary testing I've seen a 2-3x improvement in speed from an initial prototype of implementing a session data buffer before dispatch.