Skip to content

ServerHttp2Stream

[<Interface>]
type ServerHttp2Stream =
    abstract member headersSent: bool
    abstract member pushAllowed: bool
    abstract member ``end`` (chunk: obj, encoding: BufferEncoding, ?cb: (unit -> unit)) : ServerHttp2Stream
    abstract member ``end`` (chunk: obj, ?cb: (unit -> unit)) : ServerHttp2Stream
    abstract member ``end`` (?cb: (unit -> unit)) : ServerHttp2Stream
    abstract member addListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream
    abstract member addListenerAborted (listener: unit -> unit) : ServerHttp2Stream
    abstract member addListenerClose (listener: unit -> unit) : ServerHttp2Stream
    abstract member addListenerData (listener: U2<string,NonSharedBuffer> -> unit) : ServerHttp2Stream
    abstract member addListenerDrain (listener: unit -> unit) : ServerHttp2Stream
    abstract member addListenerEnd (listener: unit -> unit) : ServerHttp2Stream
    abstract member addListenerError (listener: exn -> unit) : ServerHttp2Stream
    abstract member addListenerFinish (listener: unit -> unit) : ServerHttp2Stream
    abstract member addListenerFrameError (listener: Listener) : ServerHttp2Stream
    abstract member addListenerPipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member addListenerStreamClosed (listener: float -> unit) : ServerHttp2Stream
    abstract member addListenerTimeout (listener: unit -> unit) : ServerHttp2Stream
    abstract member addListenerTrailers (listener: Listener2) : ServerHttp2Stream
    abstract member addListenerUnpipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member addListenerWantTrailers (listener: unit -> unit) : ServerHttp2Stream
    abstract member additionalHeaders (headers: OutgoingHttpHeaders) : unit
    abstract member compose<'T when 'T :> ReadableStream> (stream: U4<'T,AsyncIterable<'T,obj,obj>,(obj -> unit),Iterable<'T,obj,obj>>, ?options: Options) : 'T
    abstract member destroy (?error: exn) : ServerHttp2Stream
    abstract member off (eventName: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream
    abstract member on (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream
    abstract member onAborted (listener: unit -> unit) : ServerHttp2Stream
    abstract member onClose (listener: unit -> unit) : ServerHttp2Stream
    abstract member onData (listener: U2<string,NonSharedBuffer> -> unit) : ServerHttp2Stream
    abstract member onDrain (listener: unit -> unit) : ServerHttp2Stream
    abstract member onEnd (listener: unit -> unit) : ServerHttp2Stream
    abstract member onError (listener: exn -> unit) : ServerHttp2Stream
    abstract member onFinish (listener: unit -> unit) : ServerHttp2Stream
    abstract member onFrameError (listener: Listener) : ServerHttp2Stream
    abstract member onPipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member onStreamClosed (listener: float -> unit) : ServerHttp2Stream
    abstract member onTimeout (listener: unit -> unit) : ServerHttp2Stream
    abstract member onTrailers (listener: Listener2) : ServerHttp2Stream
    abstract member onUnpipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member onWantTrailers (listener: unit -> unit) : ServerHttp2Stream
    abstract member once (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream
    abstract member onceAborted (listener: unit -> unit) : ServerHttp2Stream
    abstract member onceClose (listener: unit -> unit) : ServerHttp2Stream
    abstract member onceData (listener: U2<string,NonSharedBuffer> -> unit) : ServerHttp2Stream
    abstract member onceDrain (listener: unit -> unit) : ServerHttp2Stream
    abstract member onceEnd (listener: unit -> unit) : ServerHttp2Stream
    abstract member onceError (listener: exn -> unit) : ServerHttp2Stream
    abstract member onceFinish (listener: unit -> unit) : ServerHttp2Stream
    abstract member onceFrameError (listener: Listener) : ServerHttp2Stream
    abstract member oncePipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member onceStreamClosed (listener: float -> unit) : ServerHttp2Stream
    abstract member onceTimeout (listener: unit -> unit) : ServerHttp2Stream
    abstract member onceTrailers (listener: Listener2) : ServerHttp2Stream
    abstract member onceUnpipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member onceWantTrailers (listener: unit -> unit) : ServerHttp2Stream
    abstract member pause () : ServerHttp2Stream
    abstract member pipe<'T when 'T :> WritableStream> (destination: 'T, ?options: Options) : 'T
    abstract member prependListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream
    abstract member prependListenerAborted (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependListenerClose (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependListenerData (listener: U2<string,NonSharedBuffer> -> unit) : ServerHttp2Stream
    abstract member prependListenerDrain (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependListenerEnd (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependListenerError (listener: exn -> unit) : ServerHttp2Stream
    abstract member prependListenerFinish (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependListenerFrameError (listener: Listener) : ServerHttp2Stream
    abstract member prependListenerPipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member prependListenerStreamClosed (listener: float -> unit) : ServerHttp2Stream
    abstract member prependListenerTimeout (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependListenerTrailers (listener: Listener2) : ServerHttp2Stream
    abstract member prependListenerUnpipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member prependListenerWantTrailers (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependOnceListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerAborted (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerClose (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerData (listener: U2<string,NonSharedBuffer> -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerDrain (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerEnd (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerError (listener: exn -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerFinish (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerFrameError (listener: Listener) : ServerHttp2Stream
    abstract member prependOnceListenerPipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerStreamClosed (listener: float -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerTimeout (listener: unit -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerTrailers (listener: Listener2) : ServerHttp2Stream
    abstract member prependOnceListenerUnpipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member prependOnceListenerWantTrailers (listener: unit -> unit) : ServerHttp2Stream
    abstract member pushStream (headers: OutgoingHttpHeaders, ?options: StreamPriorityOptions, ?callback: Callback2) : unit
    abstract member pushStream (headers: OutgoingHttpHeaders, ?callback: Callback) : unit
    abstract member removeAllListeners (?eventName: U2<string,Symbol>) : ServerHttp2Stream
    abstract member removeListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream
    abstract member removeListenerClose (listener: unit -> unit) : ServerHttp2Stream
    abstract member removeListenerData (listener: obj -> unit) : ServerHttp2Stream
    abstract member removeListenerDrain (listener: unit -> unit) : ServerHttp2Stream
    abstract member removeListenerEnd (listener: unit -> unit) : ServerHttp2Stream
    abstract member removeListenerError (listener: exn -> unit) : ServerHttp2Stream
    abstract member removeListenerFinish (listener: unit -> unit) : ServerHttp2Stream
    abstract member removeListenerPause (listener: unit -> unit) : ServerHttp2Stream
    abstract member removeListenerPipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member removeListenerReadable (listener: unit -> unit) : ServerHttp2Stream
    abstract member removeListenerResume (listener: unit -> unit) : ServerHttp2Stream
    abstract member removeListenerUnpipe (listener: Readable -> unit) : ServerHttp2Stream
    abstract member respond (?headers: U2<OutgoingHttpHeaders,string array>, ?options: ServerStreamResponseOptions) : unit
    abstract member respondWithFD (fd: U2<float,FileHandle>, ?headers: OutgoingHttpHeaders, ?options: ServerStreamFileResponseOptions) : unit
    abstract member respondWithFile (path: string, ?headers: OutgoingHttpHeaders, ?options: ServerStreamFileResponseOptionsWithError) : unit
    abstract member resume () : ServerHttp2Stream
    abstract member setDefaultEncoding (encoding: BufferEncoding) : ServerHttp2Stream
    abstract member setEncoding (encoding: BufferEncoding) : ServerHttp2Stream
    abstract member setMaxListeners (n: float) : ServerHttp2Stream
    abstract member unpipe (?destination: WritableStream) : ServerHttp2Stream
    abstract member wrap (stream: ReadableStream) : ServerHttp2Stream
AssemblyXantham.Fable.Node
ImplementsHttp2Stream

Declared inside

Compose
Pipe
PushStream

Properties

abstract member headersSent: bool

True if headers were sent, false otherwise (read-only).

@since v8.4.0

abstract member pushAllowed: bool

Read-only property mapped to the SETTINGS_ENABLE_PUSH flag of the remote client's most recent SETTINGS frame. Will be true if the remote peer accepts push streams, false otherwise. Settings are the same for every Http2Stream in the same Http2Session.

@since v8.4.0

Methods

abstract member ``end`` (chunk: obj, encoding: BufferEncoding, ?cb: (unit -> unit)) : ServerHttp2Stream

Calling the writable.end() method signals that no more data will be written to the Writable. The optional chunk and encoding arguments allow one final additional chunk of data to be written immediately before closing the stream.

Calling the write method after calling end will raise an error.

// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!

Signals that no more data will be written, with one final chunk of data.

@since v0.9.4

Parameter
cbCallback for when the stream is finished.
chunkOptional data to write. For streams not operating in object mode, chunk must be a , , or . For object mode streams, chunk may be any JavaScript value other than null.
cbCallback for when the stream is finished.
chunkOptional data to write. For streams not operating in object mode, chunk must be a , , or . For object mode streams, chunk may be any JavaScript value other than null.
encodingThe encoding if chunk is a string
cbCallback for when the stream is finished.
abstract member ``end`` (chunk: obj, ?cb: (unit -> unit)) : ServerHttp2Stream

Calling the writable.end() method signals that no more data will be written to the Writable. The optional chunk and encoding arguments allow one final additional chunk of data to be written immediately before closing the stream.

Calling the write method after calling end will raise an error.

// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!

Signals that no more data will be written, with one final chunk of data.

@since v0.9.4

Parameter
cbCallback for when the stream is finished.
chunkOptional data to write. For streams not operating in object mode, chunk must be a , , or . For object mode streams, chunk may be any JavaScript value other than null.
cbCallback for when the stream is finished.
chunkOptional data to write. For streams not operating in object mode, chunk must be a , , or . For object mode streams, chunk may be any JavaScript value other than null.
encodingThe encoding if chunk is a string
cbCallback for when the stream is finished.
abstract member ``end`` (?cb: (unit -> unit)) : ServerHttp2Stream

Calling the writable.end() method signals that no more data will be written to the Writable. The optional chunk and encoding arguments allow one final additional chunk of data to be written immediately before closing the stream.

Calling the write method after calling end will raise an error.

// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!

Signals that no more data will be written, with one final chunk of data.

@since v0.9.4

Parameter
cbCallback for when the stream is finished.
chunkOptional data to write. For streams not operating in object mode, chunk must be a , , or . For object mode streams, chunk may be any JavaScript value other than null.
cbCallback for when the stream is finished.
chunkOptional data to write. For streams not operating in object mode, chunk must be a , , or . For object mode streams, chunk may be any JavaScript value other than null.
encodingThe encoding if chunk is a string
cbCallback for when the stream is finished.
abstract member addListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream

Event emitter The defined events on documents including:

  1. close
  2. data
  3. drain
  4. end
  5. error
  6. finish
  7. pause
  8. pipe
  9. readable
  10. resume
  11. unpipe
abstract member addListenerAborted (listener: unit -> unit) : ServerHttp2Stream
addListener(event: "aborted", listener: () => void): this
abstract member addListenerClose (listener: unit -> unit) : ServerHttp2Stream
addListener(event: "close", listener: () => void): this
abstract member addListenerData (listener: U2<string,NonSharedBuffer> -> unit) : ServerHttp2Stream
addListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this
abstract member addListenerDrain (listener: unit -> unit) : ServerHttp2Stream
addListener(event: "drain", listener: () => void): this
abstract member addListenerEnd (listener: unit -> unit) : ServerHttp2Stream
addListener(event: "end", listener: () => void): this
abstract member addListenerError (listener: exn -> unit) : ServerHttp2Stream
addListener(event: "error", listener: (err: Error) => void): this
abstract member addListenerFinish (listener: unit -> unit) : ServerHttp2Stream
addListener(event: "finish", listener: () => void): this
abstract member addListenerFrameError (listener: Listener) : ServerHttp2Stream
addListener(event: "frameError", listener: (frameType: number, errorCode: number, id: number) => void): this
abstract member addListenerPipe (listener: Readable -> unit) : ServerHttp2Stream
addListener(event: "pipe", listener: (src: stream.Readable) => void): this
abstract member addListenerStreamClosed (listener: float -> unit) : ServerHttp2Stream
addListener(event: "streamClosed", listener: (code: number) => void): this
abstract member addListenerTimeout (listener: unit -> unit) : ServerHttp2Stream
addListener(event: "timeout", listener: () => void): this
abstract member addListenerTrailers (listener: Listener2) : ServerHttp2Stream
addListener(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this
abstract member addListenerUnpipe (listener: Readable -> unit) : ServerHttp2Stream
addListener(event: "unpipe", listener: (src: stream.Readable) => void): this
abstract member addListenerWantTrailers (listener: unit -> unit) : ServerHttp2Stream
addListener(event: "wantTrailers", listener: () => void): this
abstract member additionalHeaders (headers: OutgoingHttpHeaders) : unit

Sends an additional informational HEADERS frame to the connected HTTP/2 peer.

@since v8.4.0

abstract member compose<'T when 'T :> ReadableStream> (stream: U4<'T,AsyncIterable<'T,obj,obj>,(obj -> unit),Iterable<'T,obj,obj>>, ?options: Options) : 'T
abstract member destroy (?error: exn) : ServerHttp2Stream

Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the readable stream will release any internal resources and subsequent calls to push() will be ignored.

Once destroy() has been called any further calls will be a no-op and no further errors except from _destroy() may be emitted as 'error'.

Implementors should not override this method, but instead implement readable._destroy().

@since v8.0.0

Parameter
errorError which will be passed as payload in 'error' event
abstract member off (eventName: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream

Alias for emitter.removeListener().

@since v10.0.0

abstract member on (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

server.on('connection', (stream) => {
console.log('someone connected!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
//   b
//   a
abstract member onAborted (listener: unit -> unit) : ServerHttp2Stream
on(event: "aborted", listener: () => void): this
abstract member onClose (listener: unit -> unit) : ServerHttp2Stream
on(event: "close", listener: () => void): this
abstract member onData (listener: U2<string,NonSharedBuffer> -> unit) : ServerHttp2Stream
on(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this
abstract member onDrain (listener: unit -> unit) : ServerHttp2Stream
on(event: "drain", listener: () => void): this
abstract member onEnd (listener: unit -> unit) : ServerHttp2Stream
on(event: "end", listener: () => void): this
abstract member onError (listener: exn -> unit) : ServerHttp2Stream
on(event: "error", listener: (err: Error) => void): this
abstract member onFinish (listener: unit -> unit) : ServerHttp2Stream
on(event: "finish", listener: () => void): this
abstract member onFrameError (listener: Listener) : ServerHttp2Stream
on(event: "frameError", listener: (frameType: number, errorCode: number, id: number) => void): this
abstract member onPipe (listener: Readable -> unit) : ServerHttp2Stream
on(event: "pipe", listener: (src: stream.Readable) => void): this
abstract member onStreamClosed (listener: float -> unit) : ServerHttp2Stream
on(event: "streamClosed", listener: (code: number) => void): this
abstract member onTimeout (listener: unit -> unit) : ServerHttp2Stream
on(event: "timeout", listener: () => void): this
abstract member onTrailers (listener: Listener2) : ServerHttp2Stream
on(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this
abstract member onUnpipe (listener: Readable -> unit) : ServerHttp2Stream
on(event: "unpipe", listener: (src: stream.Readable) => void): this
abstract member onWantTrailers (listener: unit -> unit) : ServerHttp2Stream
on(event: "wantTrailers", listener: () => void): this
abstract member once (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream

Adds a one-timelistener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
//   b
//   a
abstract member onceAborted (listener: unit -> unit) : ServerHttp2Stream
once(event: "aborted", listener: () => void): this
abstract member onceClose (listener: unit -> unit) : ServerHttp2Stream
once(event: "close", listener: () => void): this
abstract member onceData (listener: U2<string,NonSharedBuffer> -> unit) : ServerHttp2Stream
once(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this
abstract member onceDrain (listener: unit -> unit) : ServerHttp2Stream
once(event: "drain", listener: () => void): this
abstract member onceEnd (listener: unit -> unit) : ServerHttp2Stream
once(event: "end", listener: () => void): this
abstract member onceError (listener: exn -> unit) : ServerHttp2Stream
once(event: "error", listener: (err: Error) => void): this
abstract member onceFinish (listener: unit -> unit) : ServerHttp2Stream
once(event: "finish", listener: () => void): this
abstract member onceFrameError (listener: Listener) : ServerHttp2Stream
once(event: "frameError", listener: (frameType: number, errorCode: number, id: number) => void): this
abstract member oncePipe (listener: Readable -> unit) : ServerHttp2Stream
once(event: "pipe", listener: (src: stream.Readable) => void): this
abstract member onceStreamClosed (listener: float -> unit) : ServerHttp2Stream
once(event: "streamClosed", listener: (code: number) => void): this
abstract member onceTimeout (listener: unit -> unit) : ServerHttp2Stream
once(event: "timeout", listener: () => void): this
abstract member onceTrailers (listener: Listener2) : ServerHttp2Stream
once(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this
abstract member onceUnpipe (listener: Readable -> unit) : ServerHttp2Stream
once(event: "unpipe", listener: (src: stream.Readable) => void): this
abstract member onceWantTrailers (listener: unit -> unit) : ServerHttp2Stream
once(event: "wantTrailers", listener: () => void): this
abstract member pause () : ServerHttp2Stream

The readable.pause() method will cause a stream in flowing mode to stop emitting 'data' events, switching out of flowing mode. Any data that becomes available will remain in the internal buffer.

const readable = getReadableStreamSomehow();
readable.on('data', (chunk) => {
console.log(`Received ${chunk.length} bytes of data.`);
readable.pause();
console.log('There will be no additional data for 1 second.');
setTimeout(() => {
console.log('Now data will start flowing again.');
readable.resume();
}, 1000);
});

The readable.pause() method has no effect if there is a 'readable' event listener.

@since v0.9.4

abstract member pipe<'T when 'T :> WritableStream> (destination: 'T, ?options: Options) : 'T
abstract member prependListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream

Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

server.prependListener('connection', (stream) => {
console.log('someone connected!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

abstract member prependListenerAborted (listener: unit -> unit) : ServerHttp2Stream
prependListener(event: "aborted", listener: () => void): this
abstract member prependListenerClose (listener: unit -> unit) : ServerHttp2Stream
prependListener(event: "close", listener: () => void): this
abstract member prependListenerData (listener: U2<string,NonSharedBuffer> -> unit) : ServerHttp2Stream
prependListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this
abstract member prependListenerDrain (listener: unit -> unit) : ServerHttp2Stream
prependListener(event: "drain", listener: () => void): this
abstract member prependListenerEnd (listener: unit -> unit) : ServerHttp2Stream
prependListener(event: "end", listener: () => void): this
abstract member prependListenerError (listener: exn -> unit) : ServerHttp2Stream
prependListener(event: "error", listener: (err: Error) => void): this
abstract member prependListenerFinish (listener: unit -> unit) : ServerHttp2Stream
prependListener(event: "finish", listener: () => void): this
abstract member prependListenerFrameError (listener: Listener) : ServerHttp2Stream
prependListener(event: "frameError", listener: (frameType: number, errorCode: number, id: number) => void): this
abstract member prependListenerPipe (listener: Readable -> unit) : ServerHttp2Stream
prependListener(event: "pipe", listener: (src: stream.Readable) => void): this
abstract member prependListenerStreamClosed (listener: float -> unit) : ServerHttp2Stream
prependListener(event: "streamClosed", listener: (code: number) => void): this
abstract member prependListenerTimeout (listener: unit -> unit) : ServerHttp2Stream
prependListener(event: "timeout", listener: () => void): this
abstract member prependListenerTrailers (listener: Listener2) : ServerHttp2Stream
prependListener(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this
abstract member prependListenerUnpipe (listener: Readable -> unit) : ServerHttp2Stream
prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this
abstract member prependListenerWantTrailers (listener: unit -> unit) : ServerHttp2Stream
prependListener(event: "wantTrailers", listener: () => void): this
abstract member prependOnceListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream

Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

abstract member prependOnceListenerAborted (listener: unit -> unit) : ServerHttp2Stream
prependOnceListener(event: "aborted", listener: () => void): this
abstract member prependOnceListenerClose (listener: unit -> unit) : ServerHttp2Stream
prependOnceListener(event: "close", listener: () => void): this
abstract member prependOnceListenerData (listener: U2<string,NonSharedBuffer> -> unit) : ServerHttp2Stream
prependOnceListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this
abstract member prependOnceListenerDrain (listener: unit -> unit) : ServerHttp2Stream
prependOnceListener(event: "drain", listener: () => void): this
abstract member prependOnceListenerEnd (listener: unit -> unit) : ServerHttp2Stream
prependOnceListener(event: "end", listener: () => void): this
abstract member prependOnceListenerError (listener: exn -> unit) : ServerHttp2Stream
prependOnceListener(event: "error", listener: (err: Error) => void): this
abstract member prependOnceListenerFinish (listener: unit -> unit) : ServerHttp2Stream
prependOnceListener(event: "finish", listener: () => void): this
abstract member prependOnceListenerFrameError (listener: Listener) : ServerHttp2Stream
prependOnceListener(event: "frameError", listener: (frameType: number, errorCode: number, id: number) => void): this
abstract member prependOnceListenerPipe (listener: Readable -> unit) : ServerHttp2Stream
prependOnceListener(event: "pipe", listener: (src: stream.Readable) => void): this
abstract member prependOnceListenerStreamClosed (listener: float -> unit) : ServerHttp2Stream
prependOnceListener(event: "streamClosed", listener: (code: number) => void): this
abstract member prependOnceListenerTimeout (listener: unit -> unit) : ServerHttp2Stream
prependOnceListener(event: "timeout", listener: () => void): this
abstract member prependOnceListenerTrailers (listener: Listener2) : ServerHttp2Stream
prependOnceListener(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this
abstract member prependOnceListenerUnpipe (listener: Readable -> unit) : ServerHttp2Stream
prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this
abstract member prependOnceListenerWantTrailers (listener: unit -> unit) : ServerHttp2Stream
prependOnceListener(event: "wantTrailers", listener: () => void): this
abstract member pushStream (headers: OutgoingHttpHeaders, ?options: StreamPriorityOptions, ?callback: Callback2) : unit

Initiates a push stream. The callback is invoked with the new Http2Stream instance created for the push stream passed as the second argument, or an Error passed as the first argument.

import http2 from 'node:http2';
const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond({ ':status': 200 });
stream.pushStream({ ':path': '/' }, (err, pushStream, headers) => {
if (err) throw err;
pushStream.respond({ ':status': 200 });
pushStream.end('some pushed data');
});
stream.end('some data');
});

Setting the weight of a push stream is not allowed in the HEADERS frame. Pass a weight value to http2stream.priority with the silent option set to true to enable server-side bandwidth balancing between concurrent streams.

Calling http2stream.pushStream() from within a pushed stream is not permitted and will throw an error.

@since v8.4.0

Parameter
callbackCallback that is called once the push stream has been initiated.
abstract member pushStream (headers: OutgoingHttpHeaders, ?callback: Callback) : unit

Initiates a push stream. The callback is invoked with the new Http2Stream instance created for the push stream passed as the second argument, or an Error passed as the first argument.

import http2 from 'node:http2';
const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond({ ':status': 200 });
stream.pushStream({ ':path': '/' }, (err, pushStream, headers) => {
if (err) throw err;
pushStream.respond({ ':status': 200 });
pushStream.end('some pushed data');
});
stream.end('some data');
});

Setting the weight of a push stream is not allowed in the HEADERS frame. Pass a weight value to http2stream.priority with the silent option set to true to enable server-side bandwidth balancing between concurrent streams.

Calling http2stream.pushStream() from within a pushed stream is not permitted and will throw an error.

@since v8.4.0

Parameter
callbackCallback that is called once the push stream has been initiated.
abstract member removeAllListeners (?eventName: U2<string,Symbol>) : ServerHttp2Stream

Removes all listeners, or those of the specified eventName.

It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

Returns a reference to the EventEmitter, so that calls can be chained.

@since v0.1.26

abstract member removeListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Stream

Removes the specified listener from the listener array for the event named eventName.

const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);

removeListener() will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified eventName, then removeListener() must be called multiple times to remove each instance.

Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any removeListener() or removeAllListeners() calls after emitting and before the last listener finishes execution will not remove them fromemit() in progress. Subsequent events behave as expected.

import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();

const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};

const callbackB = () => {
console.log('B');
};

myEmitter.on('event', callbackA);

myEmitter.on('event', callbackB);

// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
//   A
//   B

// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
//   A

Because listeners are managed using an internal array, calling this will change the position indices of any listener registered after the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the emitter.listeners() method will need to be recreated.

When a single function has been added as a handler multiple times for a single event (as in the example below), removeListener() will remove the most recently added instance. In the example the once('ping') listener is removed:

import { EventEmitter } from 'node:events';
const ee = new EventEmitter();

function pong() {
console.log('pong');
}

ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);

ee.emit('ping');
ee.emit('ping');

Returns a reference to the EventEmitter, so that calls can be chained.

abstract member removeListenerClose (listener: unit -> unit) : ServerHttp2Stream
removeListener(event: "close", listener: () => void): this
abstract member removeListenerData (listener: obj -> unit) : ServerHttp2Stream
removeListener(event: "data", listener: (chunk: any) => void): this
abstract member removeListenerDrain (listener: unit -> unit) : ServerHttp2Stream
removeListener(event: "drain", listener: () => void): this
abstract member removeListenerEnd (listener: unit -> unit) : ServerHttp2Stream
removeListener(event: "end", listener: () => void): this
abstract member removeListenerError (listener: exn -> unit) : ServerHttp2Stream
removeListener(event: "error", listener: (err: Error) => void): this
abstract member removeListenerFinish (listener: unit -> unit) : ServerHttp2Stream
removeListener(event: "finish", listener: () => void): this
abstract member removeListenerPause (listener: unit -> unit) : ServerHttp2Stream
removeListener(event: "pause", listener: () => void): this
abstract member removeListenerPipe (listener: Readable -> unit) : ServerHttp2Stream
removeListener(event: "pipe", listener: (src: Readable) => void): this
abstract member removeListenerReadable (listener: unit -> unit) : ServerHttp2Stream
removeListener(event: "readable", listener: () => void): this
abstract member removeListenerResume (listener: unit -> unit) : ServerHttp2Stream
removeListener(event: "resume", listener: () => void): this
abstract member removeListenerUnpipe (listener: Readable -> unit) : ServerHttp2Stream
removeListener(event: "unpipe", listener: (src: Readable) => void): this
abstract member respond (?headers: U2<OutgoingHttpHeaders,string array>, ?options: ServerStreamResponseOptions) : unit
import http2 from 'node:http2';
const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond({ ':status': 200 });
stream.end('some data');
});

Initiates a response. When the options.waitForTrailers option is set, the 'wantTrailers' event will be emitted immediately after queuing the last chunk of payload data to be sent. The http2stream.sendTrailers() method can then be used to send trailing header fields to the peer.

When options.waitForTrailers is set, the Http2Stream will not automatically close when the final DATA frame is transmitted. User code must call either http2stream.sendTrailers() or http2stream.close() to close the Http2Stream.

import http2 from 'node:http2';
const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond({ ':status': 200 }, { waitForTrailers: true });
stream.on('wantTrailers', () => {
stream.sendTrailers({ ABC: 'some value to send' });
});
stream.end('some data');
});

@since v8.4.0

abstract member respondWithFD (fd: U2<float,FileHandle>, ?headers: OutgoingHttpHeaders, ?options: ServerStreamFileResponseOptions) : unit

Initiates a response whose data is read from the given file descriptor. No validation is performed on the given file descriptor. If an error occurs while attempting to read data using the file descriptor, the Http2Stream will be closed using an RST_STREAM frame using the standard INTERNAL_ERROR code.

When used, the Http2Stream object's Duplex interface will be closed automatically.

import http2 from 'node:http2';
import fs from 'node:fs';

const server = http2.createServer();
server.on('stream', (stream) => {
const fd = fs.openSync('/some/file', 'r');

const stat = fs.fstatSync(fd);
const headers = {
'content-length': stat.size,
'last-modified': stat.mtime.toUTCString(),
'content-type': 'text/plain; charset=utf-8',
};
stream.respondWithFD(fd, headers);
stream.on('close', () => fs.closeSync(fd));
});

The optional options.statCheck function may be specified to give user code an opportunity to set additional content headers based on the fs.Stat details of the given fd. If the statCheck function is provided, the http2stream.respondWithFD() method will perform an fs.fstat() call to collect details on the provided file descriptor.

The offset and length options may be used to limit the response to a specific range subset. This can be used, for instance, to support HTTP Range requests.

The file descriptor or FileHandle is not closed when the stream is closed, so it will need to be closed manually once it is no longer needed. Using the same file descriptor concurrently for multiple streams is not supported and may result in data loss. Re-using a file descriptor after a stream has finished is supported.

When the options.waitForTrailers option is set, the 'wantTrailers' event will be emitted immediately after queuing the last chunk of payload data to be sent. The http2stream.sendTrailers() method can then be used to sent trailing header fields to the peer.

When options.waitForTrailers is set, the Http2Stream will not automatically close when the final DATA frame is transmitted. User code must call either http2stream.sendTrailers() or http2stream.close() to close the Http2Stream.

import http2 from 'node:http2';
import fs from 'node:fs';

const server = http2.createServer();
server.on('stream', (stream) => {
const fd = fs.openSync('/some/file', 'r');

const stat = fs.fstatSync(fd);
const headers = {
'content-length': stat.size,
'last-modified': stat.mtime.toUTCString(),
'content-type': 'text/plain; charset=utf-8',
};
stream.respondWithFD(fd, headers, { waitForTrailers: true });
stream.on('wantTrailers', () => {
stream.sendTrailers({ ABC: 'some value to send' });
});

stream.on('close', () => fs.closeSync(fd));
});

@since v8.4.0

Parameter
fdA readable file descriptor.
abstract member respondWithFile (path: string, ?headers: OutgoingHttpHeaders, ?options: ServerStreamFileResponseOptionsWithError) : unit

Sends a regular file as the response. The path must specify a regular file or an 'error' event will be emitted on the Http2Stream object.

When used, the Http2Stream object's Duplex interface will be closed automatically.

The optional options.statCheck function may be specified to give user code an opportunity to set additional content headers based on the fs.Stat details of the given file:

If an error occurs while attempting to read the file data, the Http2Stream will be closed using an RST_STREAM frame using the standard INTERNAL_ERROR code. If the onError callback is defined, then it will be called. Otherwise, the stream will be destroyed.

Example using a file path:

import http2 from 'node:http2';
const server = http2.createServer();
server.on('stream', (stream) => {
function statCheck(stat, headers) {
headers['last-modified'] = stat.mtime.toUTCString();
}

function onError(err) {
// stream.respond() can throw if the stream has been destroyed by
// the other side.
try {
if (err.code === 'ENOENT') {
stream.respond({ ':status': 404 });
} else {
stream.respond({ ':status': 500 });
}
} catch (err) {
// Perform actual error handling.
console.error(err);
}
stream.end();
}

stream.respondWithFile('/some/file',
{ 'content-type': 'text/plain; charset=utf-8' },
{ statCheck, onError });
});

The options.statCheck function may also be used to cancel the send operation by returning false. For instance, a conditional request may check the stat results to determine if the file has been modified to return an appropriate 304 response:

import http2 from 'node:http2';
const server = http2.createServer();
server.on('stream', (stream) => {
function statCheck(stat, headers) {
// Check the stat here...
stream.respond({ ':status': 304 });
return false; // Cancel the send operation
}
stream.respondWithFile('/some/file',
{ 'content-type': 'text/plain; charset=utf-8' },
{ statCheck });
});

The content-length header field will be automatically set.

The offset and length options may be used to limit the response to a specific range subset. This can be used, for instance, to support HTTP Range requests.

The options.onError function may also be used to handle all the errors that could happen before the delivery of the file is initiated. The default behavior is to destroy the stream.

When the options.waitForTrailers option is set, the 'wantTrailers' event will be emitted immediately after queuing the last chunk of payload data to be sent. The http2stream.sendTrailers() method can then be used to sent trailing header fields to the peer.

When options.waitForTrailers is set, the Http2Stream will not automatically close when the final DATA frame is transmitted. User code must call eitherhttp2stream.sendTrailers() or http2stream.close() to close theHttp2Stream.

import http2 from 'node:http2';
const server = http2.createServer();
server.on('stream', (stream) => {
stream.respondWithFile('/some/file',
{ 'content-type': 'text/plain; charset=utf-8' },
{ waitForTrailers: true });
stream.on('wantTrailers', () => {
stream.sendTrailers({ ABC: 'some value to send' });
});
});

@since v8.4.0

abstract member resume () : ServerHttp2Stream

The readable.resume() method causes an explicitly paused Readable stream to resume emitting 'data' events, switching the stream into flowing mode.

The readable.resume() method can be used to fully consume the data from a stream without actually processing any of that data:

getReadableStreamSomehow()
.resume()
.on('end', () => {
console.log('Reached the end, but did not read anything.');
});

The readable.resume() method has no effect if there is a 'readable' event listener.

@since v0.9.4

abstract member setDefaultEncoding (encoding: BufferEncoding) : ServerHttp2Stream

The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.

@since v0.11.15

Parameter
encodingThe new default encoding
abstract member setEncoding (encoding: BufferEncoding) : ServerHttp2Stream

The readable.setEncoding() method sets the character encoding for data read from the Readable stream.

By default, no encoding is assigned and stream data will be returned as Buffer objects. Setting an encoding causes the stream data to be returned as strings of the specified encoding rather than as Buffer objects. For instance, calling readable.setEncoding('utf8') will cause the output data to be interpreted as UTF-8 data, and passed as strings. Calling readable.setEncoding('hex') will cause the data to be encoded in hexadecimal string format.

The Readable stream will properly handle multi-byte characters delivered through the stream that would otherwise become improperly decoded if simply pulled from the stream as Buffer objects.

const readable = getReadableStreamSomehow();
readable.setEncoding('utf8');
readable.on('data', (chunk) => {
assert.equal(typeof chunk, 'string');
console.log('Got %d characters of string data:', chunk.length);
});

@since v0.9.4

Parameter
encodingThe encoding to use.
abstract member setMaxListeners (n: float) : ServerHttp2Stream

By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.

Returns a reference to the EventEmitter, so that calls can be chained.

@since v0.3.5

abstract member unpipe (?destination: WritableStream) : ServerHttp2Stream

The readable.unpipe() method detaches a Writable stream previously attached using the pipe method.

If the destination is not specified, then all pipes are detached.

If the destination is specified, but no pipe is set up for it, then the method does nothing.

import fs from 'node:fs';
const readable = getReadableStreamSomehow();
const writable = fs.createWriteStream('file.txt');
// All the data from readable goes into 'file.txt',
// but only for the first second.
readable.pipe(writable);
setTimeout(() => {
console.log('Stop writing to file.txt.');
readable.unpipe(writable);
console.log('Manually close the file stream.');
writable.end();
}, 1000);

@since v0.9.4

Parameter
destinationOptional specific stream to unpipe
abstract member wrap (stream: ReadableStream) : ServerHttp2Stream

Prior to Node.js 0.10, streams did not implement the entire node:stream module API as it is currently defined. (See Compatibility for more information.)

When using an older Node.js library that emits 'data' events and has a pause method that is advisory only, the readable.wrap() method can be used to create a Readable stream that uses the old stream as its data source.

It will rarely be necessary to use readable.wrap() but the method has been provided as a convenience for interacting with older Node.js applications and libraries.

import { OldReader } from './old-api-module.js';
import { Readable } from 'node:stream';
const oreader = new OldReader();
const myReader = new Readable().wrap(oreader);

myReader.on('readable', () => {
myReader.read(); // etc.
});

@since v0.9.4

Parameter
streamAn "old style" readable stream