options
{Object}allowHTTP1
{boolean} Incoming client connections that do not support HTTP/2 will be downgraded to HTTP/1.x when set totrue
. See the ['unknownProtocol'
][] event. See [ALPN negotiation][]. Default:false
.maxDeflateDynamicTableSize
{number} Sets the maximum dynamic table size for deflating header fields. Default:4Kib
.maxSettings
{number} Sets the maximum number of settings entries perSETTINGS
frame. The minimum value allowed is1
. Default:32
.maxSessionMemory
{number} Sets the maximum memory that theHttp2Session
is permitted to use. The value is expressed in terms of number of megabytes, e.g.1
equal 1 megabyte. The minimum value allowed is1
. This is a credit based limit, existingHttp2Stream
s may cause this limit to be exceeded, but newHttp2Stream
instances will be rejected while this limit is exceeded. The current number ofHttp2Stream
sessions, the current memory use of the header compression tables, current data queued to be sent, and unacknowledgedPING
andSETTINGS
frames are all counted towards the current limit. Default:10
.maxHeaderListPairs
{number} Sets the maximum number of header entries. This is similar to [http.Server#maxHeadersCount
][] or [http.ClientRequest#maxHeadersCount
][]. The minimum value is4
. Default:128
.maxOutstandingPings
{number} Sets the maximum number of outstanding, unacknowledged pings. Default:10
.maxSendHeaderBlockLength
{number} Sets the maximum allowed size for a serialized, compressed block of headers. Attempts to send headers that exceed this limit will result in a'frameError'
event being emitted and the stream being closed and destroyed.paddingStrategy
{number} Strategy used for determining the amount of padding to use forHEADERS
andDATA
frames. Default:http2.constants.PADDING_STRATEGY_NONE
. Value may be one of:http2.constants.PADDING_STRATEGY_NONE
: No padding is applied.http2.constants.PADDING_STRATEGY_MAX
: The maximum amount of padding, determined by the internal implementation, is applied.http2.constants.PADDING_STRATEGY_ALIGNED
: Attempts to apply enough padding to ensure that the total frame length, including the 9-byte header, is a multiple of 8. For each frame, there is a maximum allowed number of padding bytes that is determined by current flow control state and settings. If this maximum is less than the calculated amount needed to ensure alignment, the maximum is used and the total frame length is not necessarily aligned at 8 bytes.
peerMaxConcurrentStreams
{number} Sets the maximum number of concurrent streams for the remote peer as if aSETTINGS
frame had been received. Will be overridden if the remote peer sets its own value formaxConcurrentStreams
. Default:100
.maxSessionInvalidFrames
{integer} Sets the maximum number of invalid frames that will be tolerated before the session is closed. Default:1000
.maxSessionRejectedStreams
{integer} Sets the maximum number of rejected upon creation streams that will be tolerated before the session is closed. Each rejection is associated with anNGHTTP2_ENHANCE_YOUR_CALM
error that should tell the peer to not open any more streams, continuing to open streams is therefore regarded as a sign of a misbehaving peer. Default:100
.settings
{HTTP/2 Settings Object} The initial settings to send to the remote peer upon connection.- …: Any [
tls.createServer()
][] options can be provided. For servers, the identity options (pfx
orkey
/cert
) are usually required. origins
{string[]} An array of origin strings to send within anORIGIN
frame immediately following creation of a new serverHttp2Session
.
onRequestHandler
{Function} See [Compatibility API][]- Returns: {Http2SecureServer}
Returns a tls.Server
instance that creates and manages Http2Session
instances.
const http2 = require('http2');
const fs = require('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(80);