HTTP/2

Ingenium ships two HTTP/2 adapters: Http2cAdapter for cleartext HTTP/2 (h2c) and Http2Adapter for TLS HTTP/2 (h2). Both are built on node:http2.

Usage

import { ingenium, Http2Adapter, Http2cAdapter } from 'ingenium'
import { readFileSync } from 'node:fs'

// h2c (cleartext HTTP/2)
const app = ingenium({ transport: new Http2cAdapter() })
await app.listen(3000)

// h2 (TLS)
const tlsApp = ingenium({
  transport: new Http2Adapter({
    cert: readFileSync('cert.pem'),
    key: readFileSync('key.pem'),
    allowHttp1: true,           // ALPN fallback to HTTP/1.1
  }),
})
await tlsApp.listen(443)

Behavior

  • Pseudo-headers - :method, :path, :status, :scheme, :authority are handled internally. User code reads regular headers via ctx.headers.
  • Transfer-Encoding - Transfer-Encoding: chunked is stripped from responses. HTTP/2 has implicit framing, so explicit chunked encoding is invalid on the wire.
  • ALPN fallback - allowHttp1: true on Http2Adapter lets clients negotiate HTTP/1.1 if they don't speak HTTP/2.

When to use which

  • Http2cAdapter - behind a TLS-terminating reverse proxy (nginx, Caddy, a CDN). The proxy speaks HTTPS to clients and h2c upstream to your app.
  • Http2Adapter - direct-to-internet TLS, or any deployment where you own the cert.

Where to next?