Skip to content

ServerHttp2Session

[<Interface>]
type ServerHttp2Session<'Http1Request, 'Http1Response, 'Http2Request, 'Http2Response when 'Http1Request :> IncomingMessageConstructor and 'Http2Request :> Http2ServerRequestConstructor> =
    abstract member server: U2<Http2SecureServer<'Http1Request,'Http1Response,'Http2Request,'Http2Response>,Http2Server<'Http1Request,'Http1Response,'Http2Request,'Http2Response>>
    abstract member addListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member addListenerConnect (listener: Listener<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member addListenerStream (listener: Listener2) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member altsvc (alt: string, originOrStream: U4<string,float,AlternativeServiceOptions,URL>) : unit
    abstract member emitConnect (session: ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>, socket: U2<Socket,TLSSocket>) : bool
    abstract member emitStream (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: float, rawHeaders: string array) : bool
    abstract member off (eventName: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member on (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member onConnect (listener: Listener<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member onStream (listener: Listener2) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member once (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member onceConnect (listener: Listener<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member onceStream (listener: Listener2) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member origin (origins: U3<string,URL,Item> array) : unit
    abstract member prependListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member prependListenerConnect (listener: Listener<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member prependListenerStream (listener: Listener2) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member prependOnceListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member prependOnceListenerConnect (listener: Listener<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member prependOnceListenerStream (listener: Listener2) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member removeAllListeners (?eventName: U2<string,Symbol>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member removeListener (eventName: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    abstract member setMaxListeners (n: float) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
AssemblyXantham.Fable.Node
ImplementsHttp2Session

Declared inside

AddListener
On
Once
Origin
PrependListener
PrependOnceListener

Properties

abstract member server: U2<Http2SecureServer<'Http1Request,'Http1Response,'Http2Request,'Http2Response>,Http2Server<'Http1Request,'Http1Response,'Http2Request,'Http2Response>>

Methods

abstract member addListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

Alias for emitter.on(eventName, listener).

abstract member addListenerConnect (listener: Listener<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
addListener(event: "connect", listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>, socket: net.Socket | tls.TLSSocket) => void): this
abstract member addListenerStream (listener: Listener2) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
addListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number, rawHeaders: string[]) => void): this
abstract member altsvc (alt: string, originOrStream: U4<string,float,AlternativeServiceOptions,URL>) : unit

Submits an ALTSVC frame (as defined by RFC 7838) to the connected client.

import http2 from 'node:http2';

const server = http2.createServer();
server.on('session', (session) => {
// Set altsvc for origin https://example.org:80
session.altsvc('h2=":8000"', 'https://example.org:80');
});

server.on('stream', (stream) => {
// Set altsvc for a specific stream
stream.session.altsvc('h2=":8000"', stream.id);
});

Sending an ALTSVC frame with a specific stream ID indicates that the alternate service is associated with the origin of the given Http2Stream.

The alt and origin string must contain only ASCII bytes and are strictly interpreted as a sequence of ASCII bytes. The special value 'clear'may be passed to clear any previously set alternative service for a given domain.

When a string is passed for the originOrStream argument, it will be parsed as a URL and the origin will be derived. For instance, the origin for the HTTP URL 'https://example.org/foo/bar' is the ASCII string'https://example.org'. An error will be thrown if either the given string cannot be parsed as a URL or if a valid origin cannot be derived.

A URL object, or any object with an origin property, may be passed asoriginOrStream, in which case the value of the origin property will be used. The value of the origin property must be a properly serialized ASCII origin.

@since v9.4.0

Parameter
altA description of the alternative service configuration as defined by RFC 7838.
originOrStreamEither a URL string specifying the origin (or an Object with an origin property) or the numeric identifier of an active Http2Stream as given by the http2stream.id property.
abstract member emitConnect (session: ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>, socket: U2<Socket,TLSSocket>) : bool
emit(event: "connect", session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>, socket: net.Socket | tls.TLSSocket): boolean
abstract member emitStream (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: float, rawHeaders: string array) : bool
emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number, rawHeaders: string[]): boolean
abstract member off (eventName: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

Alias for emitter.removeListener().

@since v10.0.0

abstract member on (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

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 onConnect (listener: Listener<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
on(event: "connect", listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>, socket: net.Socket | tls.TLSSocket) => void): this
abstract member onStream (listener: Listener2) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
on(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number, rawHeaders: string[]) => void): this
abstract member once (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

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 onceConnect (listener: Listener<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
once(event: "connect", listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>, socket: net.Socket | tls.TLSSocket) => void): this
abstract member onceStream (listener: Listener2) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
once(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number, rawHeaders: string[]) => void): this
abstract member origin (origins: U3<string,URL,Item> array) : unit

Submits an ORIGIN frame (as defined by RFC 8336) to the connected client to advertise the set of origins for which the server is capable of providing authoritative responses.

import http2 from 'node:http2';
const options = getSecureOptionsSomehow();
const server = http2.createSecureServer(options);
server.on('stream', (stream) => {
stream.respond();
stream.end('ok');
});
server.on('session', (session) => {
session.origin('https://example.com', 'https://example.org');
});

When a string is passed as an origin, it will be parsed as a URL and the origin will be derived. For instance, the origin for the HTTP URL 'https://example.org/foo/bar' is the ASCII string 'https://example.org'. An error will be thrown if either the given string cannot be parsed as a URL or if a valid origin cannot be derived.

A URL object, or any object with an origin property, may be passed as an origin, in which case the value of the origin property will be used. The value of the origin property must be a properly serialized ASCII origin.

Alternatively, the origins option may be used when creating a new HTTP/2 server using the http2.createSecureServer() method:

import http2 from 'node:http2';
const options = getSecureOptionsSomehow();
options.origins = ['https://example.com', 'https://example.org'];
const server = http2.createSecureServer(options);
server.on('stream', (stream) => {
stream.respond();
stream.end('ok');
});

@since v10.12.0

Parameter
originsOne or more URL Strings passed as separate arguments.
abstract member prependListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

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 prependListenerConnect (listener: Listener<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
prependListener(event: "connect", listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>, socket: net.Socket | tls.TLSSocket) => void): this
abstract member prependListenerStream (listener: Listener2) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
prependListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number, rawHeaders: string[]) => void): this
abstract member prependOnceListener (event: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

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 prependOnceListenerConnect (listener: Listener<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
prependOnceListener(event: "connect", listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>, socket: net.Socket | tls.TLSSocket) => void): this
abstract member prependOnceListenerStream (listener: Listener2) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
prependOnceListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number, rawHeaders: string[]) => void): this
abstract member removeAllListeners (?eventName: U2<string,Symbol>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

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 (eventName: U2<string,Symbol>, listener: obj array -> unit) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

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.

@since v0.1.26

abstract member setMaxListeners (n: float) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

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