Skip to content

Exports

[<Class>]
type Exports =
    static member constants: Constants3
    static member sensitiveHeaders: Symbol
    static member Http2ServerRequest (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, options: ReadableOptions<Readable>, rawHeaders: string array) : Http2ServerRequest
    static member Http2ServerResponse<'Request when 'Request :> Http2ServerRequest> (stream: ServerHttp2Stream) : Http2ServerResponse<'Request>
    static member connect (authority: U2<string,URL>, ?options: U2<ClientSessionOptions,SecureClientSessionOptions>, ?listener: Listener2) : ClientHttp2Session
    static member connect (authority: U2<string,URL>, listener: Listener) : ClientHttp2Session
    static member createSecureServer<'Http1Request, 'Http1Response, 'Http2Request, 'Http2Response when 'Http1Request :> IncomingMessageConstructor and 'Http2Request :> Http2ServerRequestConstructor> (options: SecureServerOptions<'Http1Request,'Http1Response,'Http2Request,'Http2Response>, ?onRequestHandler: OnRequestHandler2<'Http2Request,'Http2Response>) : Http2SecureServer<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    static member createSecureServer (?onRequestHandler: OnRequestHandler) : Http2SecureServer<IncomingMessageConstructor,ServerResponseConstructor,Http2ServerRequestConstructor,Http2ServerResponseConstructor>
    static member createServer<'Http1Request, 'Http1Response, 'Http2Request, 'Http2Response when 'Http1Request :> IncomingMessageConstructor and 'Http2Request :> Http2ServerRequestConstructor> (options: ServerOptions<'Http1Request,'Http1Response,'Http2Request,'Http2Response>, ?onRequestHandler: OnRequestHandler2<'Http2Request,'Http2Response>) : Http2Server<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
    static member createServer (?onRequestHandler: OnRequestHandler) : Http2Server<IncomingMessageConstructor,ServerResponseConstructor,Http2ServerRequestConstructor,Http2ServerResponseConstructor>
    static member getDefaultSettings () : Settings
    static member getPackedSettings (settings: Settings) : NonSharedBuffer
    static member getUnpackedSettings (buf: Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>) : Settings
    static member performServerHandshake<'Http1Request, 'Http1Response, 'Http2Request, 'Http2Response when 'Http1Request :> IncomingMessageConstructor and 'Http2Request :> Http2ServerRequestConstructor> (socket: Duplex, ?options: ServerOptions<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>
AssemblyXantham.Fable.Node
Attributes[<Erase>]

The package's value exports, each bound to its import.

Properties

static member constants: Constants3
static member sensitiveHeaders: Symbol

This symbol can be set as a property on the HTTP/2 headers object with an array value in order to provide a list of headers considered sensitive.

Methods

static member Http2ServerRequest (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, options: ReadableOptions<Readable>, rawHeaders: string array) : Http2ServerRequest

A Http2ServerRequest object is created by Server or SecureServer and passed as the first argument to the 'request' event. It may be used to access a request status, headers, and data.

@since v8.4.0

static member Http2ServerResponse<'Request when 'Request :> Http2ServerRequest> (stream: ServerHttp2Stream) : Http2ServerResponse<'Request>

This object is created internally by an HTTP server, not by the user. It is passed as the second parameter to the 'request' event.

@since v8.4.0

static member connect (authority: U2<string,URL>, ?options: U2<ClientSessionOptions,SecureClientSessionOptions>, ?listener: Listener2) : ClientHttp2Session

Returns a ClientHttp2Session instance.

import http2 from 'node:http2';
const client = http2.connect('https://localhost:1234');

// Use the client

client.close();

@since v8.4.0

Parameter
authorityThe remote HTTP/2 server to connect to. This must be in the form of a minimal, valid URL with the http:// or https:// prefix, host name, and IP port (if a non-default port is used). Userinfo (user ID and password), path, querystring, and fragment details in the URL will be ignored.
listenerWill be registered as a one-time listener of the {@link 'connect'} event.
static member connect (authority: U2<string,URL>, listener: Listener) : ClientHttp2Session

Returns a ClientHttp2Session instance.

import http2 from 'node:http2';
const client = http2.connect('https://localhost:1234');

// Use the client

client.close();

@since v8.4.0

Parameter
authorityThe remote HTTP/2 server to connect to. This must be in the form of a minimal, valid URL with the http:// or https:// prefix, host name, and IP port (if a non-default port is used). Userinfo (user ID and password), path, querystring, and fragment details in the URL will be ignored.
listenerWill be registered as a one-time listener of the {@link 'connect'} event.
static member createSecureServer<'Http1Request, 'Http1Response, 'Http2Request, 'Http2Response when 'Http1Request :> IncomingMessageConstructor and 'Http2Request :> Http2ServerRequestConstructor> (options: SecureServerOptions<'Http1Request,'Http1Response,'Http2Request,'Http2Response>, ?onRequestHandler: OnRequestHandler2<'Http2Request,'Http2Response>) : Http2SecureServer<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

Returns a tls.Server instance that creates and manages Http2Session instances.

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

const options = {
key: fs.readFileSync('server-key.pem'),
cert: fs.readFileSync('server-cert.pem'),
};

// Create a secure HTTP/2 server
const server = http2.createSecureServer(options);

server.on('stream', (stream, headers) => {
stream.respond({
'content-type': 'text/html; charset=utf-8',
':status': 200,
});
stream.end('<h1>Hello World</h1>');
});

server.listen(8443);

@since v8.4.0

Parameter
onRequestHandlerSee Compatibility API
static member createSecureServer (?onRequestHandler: OnRequestHandler) : Http2SecureServer<IncomingMessageConstructor,ServerResponseConstructor,Http2ServerRequestConstructor,Http2ServerResponseConstructor>

Returns a tls.Server instance that creates and manages Http2Session instances.

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

const options = {
key: fs.readFileSync('server-key.pem'),
cert: fs.readFileSync('server-cert.pem'),
};

// Create a secure HTTP/2 server
const server = http2.createSecureServer(options);

server.on('stream', (stream, headers) => {
stream.respond({
'content-type': 'text/html; charset=utf-8',
':status': 200,
});
stream.end('<h1>Hello World</h1>');
});

server.listen(8443);

@since v8.4.0

Parameter
onRequestHandlerSee Compatibility API
static member createServer<'Http1Request, 'Http1Response, 'Http2Request, 'Http2Response when 'Http1Request :> IncomingMessageConstructor and 'Http2Request :> Http2ServerRequestConstructor> (options: ServerOptions<'Http1Request,'Http1Response,'Http2Request,'Http2Response>, ?onRequestHandler: OnRequestHandler2<'Http2Request,'Http2Response>) : Http2Server<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

Returns a net.Server instance that creates and manages Http2Session instances.

Since there are no browsers known that support unencrypted HTTP/2, the use of createSecureServer is necessary when communicating with browser clients.

import http2 from 'node:http2';

// Create an unencrypted HTTP/2 server.
// Since there are no browsers known that support
// unencrypted HTTP/2, the use of `http2.createSecureServer()`
// is necessary when communicating with browser clients.
const server = http2.createServer();

server.on('stream', (stream, headers) => {
stream.respond({
'content-type': 'text/html; charset=utf-8',
':status': 200,
});
stream.end('<h1>Hello World</h1>');
});

server.listen(8000);

@since v8.4.0

Parameter
onRequestHandlerSee Compatibility API
static member createServer (?onRequestHandler: OnRequestHandler) : Http2Server<IncomingMessageConstructor,ServerResponseConstructor,Http2ServerRequestConstructor,Http2ServerResponseConstructor>

Returns a net.Server instance that creates and manages Http2Session instances.

Since there are no browsers known that support unencrypted HTTP/2, the use of createSecureServer is necessary when communicating with browser clients.

import http2 from 'node:http2';

// Create an unencrypted HTTP/2 server.
// Since there are no browsers known that support
// unencrypted HTTP/2, the use of `http2.createSecureServer()`
// is necessary when communicating with browser clients.
const server = http2.createServer();

server.on('stream', (stream, headers) => {
stream.respond({
'content-type': 'text/html; charset=utf-8',
':status': 200,
});
stream.end('<h1>Hello World</h1>');
});

server.listen(8000);

@since v8.4.0

Parameter
onRequestHandlerSee Compatibility API
static member getDefaultSettings () : Settings

Returns an object containing the default settings for an Http2Session instance. This method returns a new object instance every time it is called so instances returned may be safely modified for use.

@since v8.4.0

static member getPackedSettings (settings: Settings) : NonSharedBuffer

Returns a Buffer instance containing serialized representation of the given HTTP/2 settings as specified in the HTTP/2 specification. This is intended for use with the HTTP2-Settings header field.

import http2 from 'node:http2';

const packed = http2.getPackedSettings({ enablePush: false });

console.log(packed.toString('base64'));
// Prints: AAIAAAAA

@since v8.4.0

static member getUnpackedSettings (buf: Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>) : Settings

Returns a HTTP/2 Settings Object containing the deserialized settings from the given Buffer as generated by http2.getPackedSettings().

@since v8.4.0

Parameter
bufThe packed settings.
static member performServerHandshake<'Http1Request, 'Http1Response, 'Http2Request, 'Http2Response when 'Http1Request :> IncomingMessageConstructor and 'Http2Request :> Http2ServerRequestConstructor> (socket: Duplex, ?options: ServerOptions<'Http1Request,'Http1Response,'Http2Request,'Http2Response>) : ServerHttp2Session<'Http1Request,'Http1Response,'Http2Request,'Http2Response>

Create an HTTP/2 server session from an existing socket.

@since v20.12.0

Parameter
socketA Duplex Stream
optionsAny {@link createServer} options can be provided.