interface Http2Stream
The following methods are non-functional stubs:
- aborted
- bufferSize
- endAfterHeaders
- id
- pending
- priority
- rstCode
- sentHeaders
- sentInfoHeaders
- sentTrailers
- state
Properties #
Set to true if the Http2Stream instance was aborted abnormally. When set,
the 'aborted' event will have been emitted.
#bufferSize: number This property shows the number of characters currently buffered to be written.
See net.Socket.bufferSize for details.
Set to true if the Http2Stream instance has been destroyed and is no longer
usable.
#endAfterHeaders: boolean Set to true if the END_STREAM flag was set in the request or response
HEADERS frame received, indicating that no additional data should be received
and the readable side of the Http2Stream will be closed.
The numeric stream identifier of this Http2Stream instance. Set to undefined if the stream identifier has not yet been assigned.
Set to true if the Http2Stream instance has not yet been assigned a
numeric stream identifier.
Set to the RST_STREAM error code reported when the Http2Stream is
destroyed after either receiving an RST_STREAM frame from the connected peer,
calling http2stream.close(), or http2stream.destroy(). Will be undefined if the Http2Stream has not been closed.
#sentHeaders: OutgoingHttpHeaders An object containing the outbound headers sent for this Http2Stream.
#sentInfoHeaders: OutgoingHttpHeaders[] | undefined An array of objects containing the outbound informational (additional) headers
sent for this Http2Stream.
#sentTrailers: OutgoingHttpHeaders | undefined An object containing the outbound trailers sent for this HttpStream.
#session: Http2Session | undefined A reference to the Http2Session instance that owns this Http2Stream. The
value will be undefined after the Http2Stream instance is destroyed.
#state: StreamState Provides miscellaneous information about the current state of the Http2Stream.
A current state of this Http2Stream.
Methods #
Closes the Http2Stream instance by sending an RST_STREAM frame to the
connected HTTP/2 peer.
#priority(options: StreamPriorityOptions): void Updates the priority for this Http2Stream instance.
#setTimeout(msecs: number,callback?: () => void,): void import http2 from 'node:http2';
const client = http2.connect('http://example.org:8000');
const { NGHTTP2_CANCEL } = http2.constants;
const req = client.request({ ':path': '/' });
// Cancel the stream if there's no activity after 5 seconds
req.setTimeout(5000, () => req.close(NGHTTP2_CANCEL));
#sendTrailers(headers: OutgoingHttpHeaders): void Sends a trailing HEADERS frame to the connected HTTP/2 peer. This method
will cause the Http2Stream to be immediately closed and must only be
called after the 'wantTrailers' event has been emitted. When sending a
request or sending a response, the options.waitForTrailers option must be set
in order to keep the Http2Stream open after the final DATA frame so that
trailers can be sent.
import http2 from 'node:http2';
const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond(undefined, { waitForTrailers: true });
stream.on('wantTrailers', () => {
stream.sendTrailers({ xyz: 'abc' });
});
stream.end('Hello World');
});
The HTTP/1 specification forbids trailers from containing HTTP/2 pseudo-header
fields (e.g. ':method', ':path', etc).
#addListener(event: "aborted",listener: () => void,): this #addListener(event: "close",listener: () => void,): this #addListener(event: "data",listener: (chunk: Buffer | string) => void,): this #addListener(event: "drain",listener: () => void,): this #addListener(event: "end",listener: () => void,): this #addListener(event: "error",listener: (err: Error) => void,): this #addListener(event: "finish",listener: () => void,): this #addListener(event: "frameError",listener: (frameType: number,errorCode: number,) => void,): this #addListener(event: "pipe",listener: (src: stream.Readable) => void,): this #addListener(event: "unpipe",listener: (src: stream.Readable) => void,): this #addListener(event: "streamClosed",listener: (code: number) => void,): this #addListener(event: "timeout",listener: () => void,): this #addListener(event: "trailers",listener: (trailers: IncomingHttpHeaders,flags: number,) => void,): this #addListener(event: "wantTrailers",listener: () => void,): this #addListener(event: string | symbol,listener: (...args: any[]) => void,): this #on(event: "trailers",listener: (trailers: IncomingHttpHeaders,flags: number,) => void,): this #once(event: "trailers",listener: (trailers: IncomingHttpHeaders,flags: number,) => void,): this #prependListener(event: "aborted",listener: () => void,): this #prependListener(event: "close",listener: () => void,): this #prependListener(event: "data",listener: (chunk: Buffer | string) => void,): this #prependListener(event: "drain",listener: () => void,): this #prependListener(event: "end",listener: () => void,): this #prependListener(event: "error",listener: (err: Error) => void,): this #prependListener(event: "finish",listener: () => void,): this #prependListener(event: "frameError",listener: (frameType: number,errorCode: number,) => void,): this #prependListener(event: "pipe",listener: (src: stream.Readable) => void,): this #prependListener(event: "unpipe",listener: (src: stream.Readable) => void,): this #prependListener(event: "streamClosed",listener: (code: number) => void,): this #prependListener(event: "timeout",listener: () => void,): this #prependListener(event: "trailers",listener: (trailers: IncomingHttpHeaders,flags: number,) => void,): this #prependListener(event: "wantTrailers",listener: () => void,): this #prependListener(event: string | symbol,listener: (...args: any[]) => void,): this #prependOnceListener(event: "aborted",listener: () => void,): this #prependOnceListener(event: "close",listener: () => void,): this #prependOnceListener(event: "data",listener: (chunk: Buffer | string) => void,): this #prependOnceListener(event: "drain",listener: () => void,): this #prependOnceListener(event: "end",listener: () => void,): this #prependOnceListener(event: "error",listener: (err: Error) => void,): this #prependOnceListener(event: "finish",listener: () => void,): this #prependOnceListener(event: "frameError",listener: (frameType: number,errorCode: number,) => void,): this #prependOnceListener(event: "pipe",listener: (src: stream.Readable) => void,): this #prependOnceListener(event: "unpipe",listener: (src: stream.Readable) => void,): this #prependOnceListener(event: "streamClosed",listener: (code: number) => void,): this #prependOnceListener(event: "timeout",listener: () => void,): this #prependOnceListener(event: "trailers",listener: (trailers: IncomingHttpHeaders,flags: number,) => void,): this #prependOnceListener(event: "wantTrailers",listener: () => void,): this #prependOnceListener(event: string | symbol,listener: (...args: any[]) => void,): this