Http2Session - Node documentation
interface Http2Session
extends EventEmitter

Usage in Deno

import { type Http2Session } from "node:http2";

Properties

readonly
optional
alpnProtocol: string | undefined

Value will be undefined if the Http2Session is not yet connected to a socket, h2c if the Http2Session is not connected to a TLSSocket, or will return the value of the connected TLSSocket's own alpnProtocolproperty.

readonly
closed: boolean

Will be true if this Http2Session instance has been closed, otherwisefalse.

readonly
connecting: boolean

Will be true if this Http2Session instance is still connecting, will be set to false before emitting connect event and/or calling the http2.connectcallback.

readonly
destroyed: boolean

Will be true if this Http2Session instance has been destroyed and must no longer be used, otherwise false.

readonly
optional
encrypted: boolean | undefined

Value is undefined if the Http2Session session socket has not yet been connected, true if the Http2Session is connected with a TLSSocket, and false if the Http2Session is connected to any other kind of socket or stream.

A prototype-less object describing the current local settings of thisHttp2Session. The local settings are local to _this_Http2Session instance.

readonly
optional
originSet: string[] | undefined

If the Http2Session is connected to a TLSSocket, the originSet property will return an Array of origins for which the Http2Session may be considered authoritative.

The originSet property is only available when using a secure TLS connection.

readonly
pendingSettingsAck: boolean

Indicates whether the Http2Session is currently waiting for acknowledgment of a sent SETTINGS frame. Will be true after calling thehttp2session.settings() method. Will be false once all sent SETTINGSframes have been acknowledged.

A prototype-less object describing the current remote settings of thisHttp2Session. The remote settings are set by the connected HTTP/2 peer.

readonly
socket: net.Socket | tls.TLSSocket

Returns a Proxy object that acts as a net.Socket (or tls.TLSSocket) but limits available methods to ones safe to use with HTTP/2.

destroy, emit, end, pause, read, resume, and write will throw an error with code ERR_HTTP2_NO_SOCKET_MANIPULATION. See Http2Session and Sockets for more information.

setTimeout method will be called on this Http2Session.

All other interactions will be routed directly to the socket.

Provides miscellaneous information about the current state of theHttp2Session.

An object describing the current status of this Http2Session.

readonly
type: number

The http2session.type will be equal tohttp2.constants.NGHTTP2_SESSION_SERVER if this Http2Session instance is a server, and http2.constants.NGHTTP2_SESSION_CLIENT if the instance is a client.

Methods

close(callback?: () => void): void

Gracefully closes the Http2Session, allowing any existing streams to complete on their own and preventing new Http2Stream instances from being created. Once closed, http2session.destroy()_might_ be called if there are no open Http2Stream instances.

If specified, the callback function is registered as a handler for the'close' event.

destroy(
error?: Error,
code?: number,
): void

Immediately terminates the Http2Session and the associated net.Socket ortls.TLSSocket.

Once destroyed, the Http2Session will emit the 'close' event. If erroris not undefined, an 'error' event will be emitted immediately before the'close' event.

If there are any remaining open Http2Streams associated with theHttp2Session, those will also be destroyed.

goaway(
code?: number,
lastStreamID?: number,
opaqueData?: ArrayBufferView,
): void

Transmits a GOAWAY frame to the connected peer without shutting down theHttp2Session.

ping(callback: (
err: Error | null,
duration: number,
payload: Buffer,
) => void
): boolean

Sends a PING frame to the connected HTTP/2 peer. A callback function must be provided. The method will return true if the PING was sent, falseotherwise.

The maximum number of outstanding (unacknowledged) pings is determined by themaxOutstandingPings configuration option. The default maximum is 10.

If provided, the payload must be a Buffer, TypedArray, or DataViewcontaining 8 bytes of data that will be transmitted with the PING and returned with the ping acknowledgment.

The callback will be invoked with three arguments: an error argument that will be null if the PING was successfully acknowledged, a duration argument that reports the number of milliseconds elapsed since the ping was sent and the acknowledgment was received, and a Buffer containing the 8-byte PINGpayload.

session.ping(Buffer.from('abcdefgh'), (err, duration, payload) => {
  if (!err) {
    console.log(`Ping acknowledged in ${duration} milliseconds`);
    console.log(`With payload '${payload.toString()}'`);
  }
});

If the payload argument is not specified, the default payload will be the 64-bit timestamp (little endian) marking the start of the PING duration.

ping(
payload: ArrayBufferView,
callback: (
err: Error | null,
duration: number,
payload: Buffer,
) => void
,
): boolean
ref(): void

Calls ref() on this Http2Sessioninstance's underlying net.Socket.

setLocalWindowSize(windowSize: number): void

Sets the local endpoint's window size. The windowSize is the total window size to set, not the delta.

const http2 = require('node:http2');

const server = http2.createServer();
const expectedWindowSize = 2 ** 20;
server.on('connect', (session) => {

  // Set local window size to be 2 ** 20
  session.setLocalWindowSize(expectedWindowSize);
});
setTimeout(
msecs: number,
callback?: () => void,
): void

Used to set a callback function that is called when there is no activity on the Http2Session after msecs milliseconds. The given callback is registered as a listener on the 'timeout' event.

settings(
settings: Settings,
callback?: (
err: Error | null,
settings: Settings,
duration: number,
) => void
,
): void

Updates the current local settings for this Http2Session and sends a newSETTINGS frame to the connected HTTP/2 peer.

Once called, the http2session.pendingSettingsAck property will be truewhile the session is waiting for the remote peer to acknowledge the new settings.

The new settings will not become effective until the SETTINGS acknowledgment is received and the 'localSettings' event is emitted. It is possible to send multiple SETTINGS frames while acknowledgment is still pending.

unref(): void

Calls unref() on this Http2Sessioninstance's underlying net.Socket.

addListener(
event: "close",
listener: () => void,
): this
addListener(
event: "error",
listener: (err: Error) => void,
): this
addListener(
event: "frameError",
listener: (
frameType: number,
errorCode: number,
streamID: number,
) => void
,
): this
addListener(
event: "goaway",
listener: (
errorCode: number,
lastStreamID: number,
opaqueData?: Buffer,
) => void
,
): this
addListener(
event: "localSettings",
listener: (settings: Settings) => void,
): this
addListener(
event: "ping",
listener: () => void,
): this
addListener(
event: "remoteSettings",
listener: (settings: Settings) => void,
): this
addListener(
event: "timeout",
listener: () => void,
): this
addListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
emit(event: "close"): boolean
emit(
event: "error",
err: Error,
): boolean
emit(
event: "frameError",
frameType: number,
errorCode: number,
streamID: number,
): boolean
emit(
event: "goaway",
errorCode: number,
lastStreamID: number,
opaqueData?: Buffer,
): boolean
emit(
event: "localSettings",
settings: Settings,
): boolean
emit(event: "ping"): boolean
emit(
event: "remoteSettings",
settings: Settings,
): boolean
emit(event: "timeout"): boolean
emit(
event: string | symbol,
...args: any[],
): boolean
on(
event: "close",
listener: () => void,
): this
on(
event: "error",
listener: (err: Error) => void,
): this
on(
event: "frameError",
listener: (
frameType: number,
errorCode: number,
streamID: number,
) => void
,
): this
on(
event: "goaway",
listener: (
errorCode: number,
lastStreamID: number,
opaqueData?: Buffer,
) => void
,
): this
on(
event: "localSettings",
listener: (settings: Settings) => void,
): this
on(
event: "ping",
listener: () => void,
): this
on(
event: "remoteSettings",
listener: (settings: Settings) => void,
): this
on(
event: "timeout",
listener: () => void,
): this
on(
event: string | symbol,
listener: (...args: any[]) => void,
): this
once(
event: "close",
listener: () => void,
): this
once(
event: "error",
listener: (err: Error) => void,
): this
once(
event: "frameError",
listener: (
frameType: number,
errorCode: number,
streamID: number,
) => void
,
): this
once(
event: "goaway",
listener: (
errorCode: number,
lastStreamID: number,
opaqueData?: Buffer,
) => void
,
): this
once(
event: "localSettings",
listener: (settings: Settings) => void,
): this
once(
event: "ping",
listener: () => void,
): this
once(
event: "remoteSettings",
listener: (settings: Settings) => void,
): this
once(
event: "timeout",
listener: () => void,
): this
once(
event: string | symbol,
listener: (...args: any[]) => void,
): this
prependListener(
event: "close",
listener: () => void,
): this
prependListener(
event: "error",
listener: (err: Error) => void,
): this
prependListener(
event: "frameError",
listener: (
frameType: number,
errorCode: number,
streamID: number,
) => void
,
): this
prependListener(
event: "goaway",
listener: (
errorCode: number,
lastStreamID: number,
opaqueData?: Buffer,
) => void
,
): this
prependListener(
event: "localSettings",
listener: (settings: Settings) => void,
): this
prependListener(
event: "ping",
listener: () => void,
): this
prependListener(
event: "remoteSettings",
listener: (settings: Settings) => void,
): this
prependListener(
event: "timeout",
listener: () => void,
): this
prependListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
prependOnceListener(
event: "close",
listener: () => void,
): this
prependOnceListener(
event: "error",
listener: (err: Error) => void,
): this
prependOnceListener(
event: "frameError",
listener: (
frameType: number,
errorCode: number,
streamID: number,
) => void
,
): this
prependOnceListener(
event: "goaway",
listener: (
errorCode: number,
lastStreamID: number,
opaqueData?: Buffer,
) => void
,
): this
prependOnceListener(
event: "localSettings",
listener: (settings: Settings) => void,
): this
prependOnceListener(
event: "ping",
listener: () => void,
): this
prependOnceListener(
event: "remoteSettings",
listener: (settings: Settings) => void,
): this
prependOnceListener(
event: "timeout",
listener: () => void,
): this
prependOnceListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this