interface Http2Session
The following methods are non-functional stubs:
- setLocalWindowSize
- ping
- localSettings
- remoteSettings
- settings
- ref
- unref
Properties #
#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 alpnProtocol property.
Will be true if this Http2Session instance has been closed, otherwise false.
#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.connect callback.
Will be true if this Http2Session instance has been destroyed and must no
longer be used, otherwise false.
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.
#localSettings: Settings A prototype-less object describing the current local settings of this Http2Session.
The local settings are local to thisHttp2Session instance.
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.
#pendingSettingsAck: boolean Indicates whether the Http2Session is currently waiting for acknowledgment of
a sent SETTINGS frame. Will be true after calling the http2session.settings() method.
Will be false once all sent SETTINGS frames have been acknowledged.
#remoteSettings: Settings A prototype-less object describing the current remote settings of thisHttp2Session.
The remote settings are set by the connected HTTP/2 peer.
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.
#state: SessionState Provides miscellaneous information about the current state of theHttp2Session.
An object describing the current status of this Http2Session.
Methods #
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.
Immediately terminates the Http2Session and the associated net.Socket or tls.TLSSocket.
Once destroyed, the Http2Session will emit the 'close' event. If error is not undefined, an 'error' event will be emitted immediately before the 'close' event.
If there are any remaining open Http2Streams associated with the Http2Session, those will also be destroyed.
Transmits a GOAWAY frame to the connected peer without shutting down theHttp2Session.
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, false otherwise.
The maximum number of outstanding (unacknowledged) pings is determined by the maxOutstandingPings configuration option. The default maximum is 10.
If provided, the payload must be a Buffer, TypedArray, or DataView containing 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 PING payload.
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.
#setLocalWindowSize(windowSize: number): void Sets the local endpoint's window size.
The windowSize is the total window size to set, not
the delta.
import http2 from '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.
Updates the current local settings for this Http2Session and sends a new SETTINGS frame to the connected HTTP/2 peer.
Once called, the http2session.pendingSettingsAck property will be true while 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.
#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 #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