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,:authorityare handled internally. User code reads regular headers viactx.headers. - Transfer-Encoding -
Transfer-Encoding: chunkedis stripped from responses. HTTP/2 has implicit framing, so explicit chunked encoding is invalid on the wire. - ALPN fallback -
allowHttp1: trueonHttp2Adapterlets 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?
- Transports - the transport contract.
- Bun - the BunAdapter alternative.
- Trust proxy - required when a TLS-terminating proxy fronts h2c.
- Production hardening - the full prod wiring.