fastify / help

Need help with Fastify? File an Issue here.
https://www.fastify.io/
65 stars 8 forks source link

Support for http/1.1 fallback support while supporting http/2? #890

Open davitykale opened 1 year ago

davitykale commented 1 year ago

What are you trying to achieve, or the steps to reproduce?

I am trying to understand if it is possible to maintain a single Fastify server that allows for HTTP/2 requests, but also supports falling back and responding to HTTP/1.1 requests. I care about this mostly in the context of building a platform-agnostic API.

I have tried enabling http/2:

// Wrap code in markdown source tags
const fastify = require('fastify')({
  http2: true
})

But consistently get a Error: Unsupported Protocol error when attempting to also enable HTTP/1 requests.

Context

metcoder95 commented 1 year ago

Hey! This is already possible, but you must combine http2 and https options. Basically, setting http2: true, and under https set the property https. allowHTTP1: true.

i.e.

// Wrap code in markdown source tags
const fastify = require('fastify')({
  http2: true,
  https: {
    allowHTTP1: true
  }
})

The previous steps will enable the creation of an HTTP/2 server under TLS (connections without TLS are not seen often).