HTTP2

Node.js http2 module — HTTP/2 client and server utilities.

Module: node:http2 Support: Experimental Since: 1.1.0 Docs: Node.js Docs

Static Methods

🟢 createServer(options, onRequestHandler)
Creates a plaintext (non-TLS) HTTP/2 server.
🟢 createSecureServer(options, onRequestHandler)
Creates a TLS-encrypted HTTP/2 server.
🟢 connect(authority, options, listener)
Creates a client connection to an HTTP/2 server.
🟢 getDefaultSettings()
Returns a settings object containing the default HTTP/2 settings.
🟢 getPackedSettings(settings)
Packs HTTP/2 settings into a Buffer suitable for the HTTP2-Settings header.
🟢 getUnpackedSettings(buf)
Unpacks a Buffer of packed HTTP/2 settings into a settings object.

Properties

🟢 sensitiveHeaders
HTTP/2 sensitivity headers flag. Used to mark headers as sensitive
🟢 constants
HTTP/2 sensitivity headers flag. Used to mark headers as sensitive

Dictionary Http2Settings

Settings for an HTTP/2 session.

Since: 1.1.0 Docs: Node.js Docs

7 members: 7 undocumented

Properties

⚪ headerTableSize
Maximum size of the header table used for HPACK compression.
⚪ enablePush
If true, server push is permitted.
⚪ maxConcurrentStreams
Maximum number of concurrent streams allowed.
⚪ initialWindowSize
Initial window size for stream-level flow control (bytes).
⚪ maxFrameSize
Maximum frame payload size that the sender is willing to receive.
⚪ maxHeaderListSize
Maximum size of header list the sender is willing to accept.
⚪ enableConnectProtocol
If true, CONNECT protocol support is enabled (RFC 8441).

---

Dictionary Http2ServerOptions

Options for creating an HTTP/2 server.

Since: 1.1.0 Docs: Node.js Docs

7 members: 7 undocumented

Properties

⚪ maxDeflateDynamicTableSize
Maximum number of invalid frames received before the session is destroyed.
⚪ maxHeaderSize
Maximum allowed HTTP header size in bytes.
⚪ maxReservedRemoteStreams
Maximum number of reserved (push) streams per session.
⚪ maxSettings
Maximum number of settings entries received during a SETTINGS acknowledgement.
⚪ paddingStrategy
Padding strategy: 0 = none, 1 = max, 2 = callback.
⚪ peerMaxConcurrentStreams
HTTP/2 peer maximum frame size.
⚪ settings
Maximum number of reserved (push) streams per session.

---

Dictionary Http2SecureServerOptions

Options for creating a secure HTTP/2 server (TLS).

Extends: Http2ServerOptions Since: 1.1.0 Docs: Node.js Docs

11 members: 11 undocumented

Properties

⚪ allowHTTP1
If true, allow HTTP/1 upgrade for ALPN negotiation failure.
⚪ ca
Trusted CA certificates.
⚪ cert
Server certificate chain (PEM string or Buffer).
⚪ key
Server certificate chain (PEM string or Buffer).
⚪ passphrase
Passphrase to decrypt the private key.
⚪ pfx
PFX/PKCS#12 encoded private key and certificate chain.
⚪ ciphers
OpenSSL cipher suite string.
⚪ honorCipherOrder
If true, prefer the server's cipher order.
⚪ minVersion
Minimum TLS version.
⚪ maxVersion
Maximum TLS version.
⚪ ALPNProtocols
List of ALPN protocol names.

---

Dictionary Http2ConnectOptions

Options for connecting to an HTTP/2 server.

Since: 1.1.0 Docs: Node.js Docs

5 members: 5 undocumented

Properties

⚪ maxHeaderSize
Maximum allowed HTTP header size in bytes.
⚪ maxReservedRemoteStreams
Maximum number of reserved (push) streams per session.
⚪ maxSettings
Maximum number of settings entries received during a SETTINGS acknowledgement.
⚪ settings
Maximum number of reserved (push) streams per session.
⚪ rejectUnauthorized
If true, reject unauthorized TLS certificates.

---

Interface Http2Session

An HTTP/2 session represents a network connection between a client and server.

Extends: EventEmitter Implements: EventEmitter Since: 1.1.0 Docs: Node.js Docs

13 members: 12 supported, 1 undocumented

Methods

🟢 close(callback)
Gracefully closes the session; existing streams can complete.
🟢 destroy(error, code)
Immediately destroys the session, terminating all streams.
🟢 goaway(code, lastStreamID, opaqueData)
Submits a GOAWAY frame to the remote peer.
🟢 ping(payload, callback)
Sends a PING frame.
⚪ settings(settings, callback)
Maximum number of reserved (push) streams per session.
🟢 ref()
Keeps the event loop alive while the session is active.
🟢 unref()
Allows the event loop to exit even if the session is active.

Properties

🟢 destroyed
Options for creating an HTTP/2 server.
🟢 closed
— True if the session has been destroyed.
🟢 pendingSettingsAck
— True if the session is waiting for a settings acknowledgement.
🟢 alpnProtocol
— The ALPN protocol negotiated for this session.
🟢 remoteSettings
— The remote settings received from the peer.
🟢 localSettings
— The local settings for this session.

---

Interface Http2Stream

An HTTP/2 stream associated with a session.

Extends: Duplex Implements: EventEmitter Since: 1.1.0 Docs: Node.js Docs

Methods

🟢 close(code, callback)
Gracefully closes the session; existing streams can complete.
🟢 priority(options)
Sets the stream priority.
🟢 setTimeout(msecs, callback)
Sets a timeout on the stream.
🟢 sendTrailers(headers)
Sends trailing headers.

Properties

🟢 aborted
An HTTP/2 stream associated with a session.
🟢 closed
— True if the session has been destroyed.
🟢 destroyed
Options for creating an HTTP/2 server.
🟢 endAfterHeaders
— True if the stream has received END_STREAM.
🟢 id
— Numeric stream identifier.
🟢 pending
— Numeric stream identifier.
🟢 rstCode
— RST_STREAM error code, or undefined if the stream was not reset.
🟢 sentHeaders
— True if headers have been sent on this stream.
🟢 sentInfoHeaders
— The informational (1xx) headers that were sent, if any.
🟢 sentTrailers
— The trailing headers that were sent, if any.
🟢 session
Options for creating an HTTP/2 server.
🟢 state
— The parent Http2Session.

---