1

I have made a very simple node server using Fastify. I want to try to use HTTP2. I have followed the docs, and created the server like this:

  const fastify = Fastify({ http2: true });

But if I run it and then try to make a request using curl:

curl -kvso --http2 http://0.0.0.0:3000/health -H "Accept: application/json" -H "Content-type: application/json" --output response.json

It seems the request goes fine but I cannot the what the server is returning:

*   Trying 0.0.0.0...
* TCP_NODELAY set
* Connected to 0.0.0.0 (127.0.0.1) port 3000 (#0)
> GET /health HTTP/1.1
> Host: 0.0.0.0:3000
> User-Agent: curl/7.64.1
> Accept: application/json
> Content-type: application/json
> 
{ [9 bytes data]
* Closing connection 0

And the JSON contains binary data so I cannot see it. Any idea what's happening?

Update

I have changed the command according to the comments. Now the requests is made using HTTP/2.0 but the commands gets stuck without printing anything:

curl --http2-prior-knowledge --insecure --verbose http://0.0.0.0:3000/health -H "Accept: application/json" -H "Content-type: application/json"

Output:

*   Trying 0.0.0.0...
* TCP_NODELAY set
* Connected to 0.0.0.0 (127.0.0.1) port 3000 (#0)
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fdc0000f800)
> GET /health HTTP/2
> Host: 0.0.0.0:3000
> User-Agent: curl/7.64.1
> Accept: application/json
> Content-type: application/json
> 
* Connection state changed (MAX_CONCURRENT_STREAMS == 4294967295)!
Antonio Gamiz Delgado
  • 1,871
  • 1
  • 12
  • 33
  • 1
    Http2 requires https too, you need to provide a key to fastify – Manuel Spigolon Oct 30 '21 at 20:27
  • 1
    I note your using a `http://` URL and not `https://`. By default curl will use HTTP/1.1 (as can be seen in the output) even with the `-http2` switch for `http://` requests. If this server only supports HTTP/2 then you might want to get Curl to try that. See here for more details: https://stackoverflow.com/questions/69641525/communication-is-happening-on-http-1-1-even-though-http2-is-enabled-how-to-enfo/69642239#69642239 – Barry Pollard Oct 30 '21 at 20:28
  • Oh I did not realized it said HTTP1 on the output!! Thanks to both of you! – Antonio Gamiz Delgado Oct 31 '21 at 05:51

0 Answers0