fastify-early-hints icon indicating copy to clipboard operation
fastify-early-hints copied to clipboard

http2 vs http1 support seems backwards

Open moonmeister opened this issue 2 years ago • 14 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure the issue has not already been raised

Issue

So, in everything I've read, but most importantly, the Chrome docs, Early Hints are only supported on http2 and 3. But, this plugin throws an error if I try to set Fastify to use http2.

Is this not backwards? If correct as is, what's the reason we've disabled this on http/2? Thanks all!

moonmeister avatar Nov 03 '22 23:11 moonmeister

Is this not backwards?

It is the choice from Chromium and it does not means Early Hints is not supported in HTTP/1.1.

What's the reason we've disabled this on http/2?

I believe is the complexity of directly write to socket for HTTP/2.

climba03003 avatar Nov 04 '22 05:11 climba03003

Also we expect that fastify is behind a reverse proxy like Ingress/traefik which resolves a http2 request to http1.1 and vice versa.

Maybe we can transplant http2 from nodejs sourcecode to our plugin?

Uzlopak avatar Nov 04 '22 08:11 Uzlopak

Maybe we can transplant http2 from nodejs sourcecode to our plugin?

Yes, we can use reply.raw.stream for the reply. Details on https://nodejs.org/api/http2.html#http2streamadditionalheadersheaders

climba03003 avatar Nov 04 '22 08:11 climba03003

I think we should just use the native functionality: https://nodejs.org/api/http2.html#responsewriteearlyhintslinks.

mcollina avatar Nov 04 '22 10:11 mcollina

I think we should just use the native functionality: https://nodejs.org/api/http2.html#responsewriteearlyhintslinks.

We need to provide a compatible layer for node@14 and node@16. Patching to use additionalHeaders and .socket are needed.

And, if the native one is available, for example [email protected]. We should absolutely go into that.

climba03003 avatar Nov 04 '22 10:11 climba03003

Also we expect that fastify is behind a reverse proxy like Ingress/traefik which resolves a http2 request to http1.1 and vice versa.

That's not necessarily true. A reverse proxy can still use http/2 to communicate to the backend services.

Maybe we can transplant http2 from nodejs sourcecode to our plugin?

That would be a maintenance nightmare.

jsumners avatar Nov 04 '22 11:11 jsumners

That would be a maintenance nightmare.

Not really re-invented the wheel, http2 already provide a method called additionalHeaders. We can directly pass the header with additional :status.

climba03003 avatar Nov 04 '22 12:11 climba03003

My assessment:

  • modify formatEntry to not add "Link:" when http2
  • concat the early hints into message not with CRLF but with a comma, no trailing comma
  • use additionalHeaders instead of write on reply.raw

I am wondering how we can test http2 because undici does not support http2

Uzlopak avatar Nov 04 '22 13:11 Uzlopak

I am wondering how we can test http2 because undici does not support http2

Use built-in net or http2 package.

climba03003 avatar Nov 04 '22 13:11 climba03003

created #8 for discussing http2 implementation

Uzlopak avatar Nov 04 '22 15:11 Uzlopak

Looks like the PR was closed without resolution :-(

lilouartz avatar May 24 '24 02:05 lilouartz

Looks like the PR was closed without resolution :-(

Since, Node.js already implemented the writeEarlyHints in both http and http2. You should use the native function instead of relying this project (unless you are in old Node.js version).

climba03003 avatar May 24 '24 06:05 climba03003

ah, would be useful to document this somewhere.

lilouartz avatar May 24 '24 06:05 lilouartz

https://github.com/fastify/fastify/issues/5479

mcollina avatar May 24 '24 07:05 mcollina