Usage in Deno
import { type Http2Stream } from "node:http2";
aborted: boolean
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.
closed: boolean
Set to true
if the Http2Stream
instance has been closed.
destroyed: boolean
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.
id: number | undefined
The numeric stream identifier of this Http2Stream
instance. Set to undefined
if the stream identifier has not yet been assigned.
pending: boolean
Set to true
if the Http2Stream
instance has not yet been assigned a
numeric stream identifier.
rstCode: number
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
.
close(code?: number,callback?: () => void,): void
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
emit(event: "aborted"): boolean
emit(event: "close"): boolean
emit(event: "data",chunk: Buffer | string,): boolean
emit(event: "drain"): boolean
emit(event: "end"): boolean
emit(event: "error",err: Error,): boolean
emit(event: "finish"): boolean
emit(event: "frameError",frameType: number,errorCode: number,): boolean
emit(event: "pipe",src: stream.Readable,): boolean
emit(event: "unpipe",src: stream.Readable,): boolean
emit(event: "streamClosed",code: number,): boolean
emit(event: "timeout"): boolean
emit(): boolean
emit(event: "wantTrailers"): boolean
emit(event: string | symbol,...args: any[],): boolean
on(event: "aborted",listener: () => void,): this
on(event: "close",listener: () => void,): this
on(event: "data",listener: (chunk: Buffer | string) => void,): this
on(event: "drain",listener: () => void,): this
on(event: "end",listener: () => void,): this
on(event: "error",listener: (err: Error) => void,): this
on(event: "finish",listener: () => void,): this
on(event: "frameError",listener: (frameType: number,errorCode: number,) => void,): this
on(event: "pipe",listener: (src: stream.Readable) => void,): this
on(event: "unpipe",listener: (src: stream.Readable) => void,): this
on(event: "streamClosed",listener: (code: number) => void,): this
on(event: "timeout",listener: () => void,): this
on(event: "trailers",listener: (trailers: IncomingHttpHeaders,flags: number,) => void,): this
on(event: "wantTrailers",listener: () => void,): this
on(event: string | symbol,listener: (...args: any[]) => void,): this
once(event: "aborted",listener: () => void,): this
once(event: "close",listener: () => void,): this
once(event: "data",listener: (chunk: Buffer | string) => void,): this
once(event: "drain",listener: () => void,): this
once(event: "end",listener: () => void,): this
once(event: "error",listener: (err: Error) => void,): this
once(event: "finish",listener: () => void,): this
once(event: "frameError",listener: (frameType: number,errorCode: number,) => void,): this
once(event: "pipe",listener: (src: stream.Readable) => void,): this
once(event: "unpipe",listener: (src: stream.Readable) => void,): this
once(event: "streamClosed",listener: (code: number) => void,): this
once(event: "timeout",listener: () => void,): this
once(event: "trailers",listener: (trailers: IncomingHttpHeaders,flags: number,) => void,): this
once(event: "wantTrailers",listener: () => void,): this
once(event: string | symbol,listener: (...args: any[]) => 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