8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c57cd9b commit bdcbe81Copy full SHA for bdcbe81
lib/internal/http2/core.js
@@ -28,6 +28,8 @@ const { _connectionListener: httpConnectionListener } = require('http');
28
const { createPromise, promiseResolve } = process.binding('util');
29
const debug = util.debuglog('http2');
30
31
+const kMaxFrameSize = (2 ** 24) - 1;
32
+const kMaxInt = (2 ** 32) - 1;
33
const kMaxStreams = (2 ** 31) - 1;
34
35
const {
@@ -330,9 +332,9 @@ function emitGoaway(self, code, lastStreamID, buf) {
330
332
return;
331
333
if (!state.shuttingDown && !state.shutdown) {
334
self.shutdown({}, self.destroy.bind(self));
- } else {
- self.destroy();
335
+ return;
336
}
337
+ self.destroy();
338
339
340
// Called by the native layer when a goaway frame has been received
@@ -580,14 +582,15 @@ function doShutdown(options) {
580
582
function submitShutdown(options) {
581
583
const type = this[kType];
584
debug(`Http2Session ${sessionName(type)}: submitting shutdown request`);
585
+ const fn = doShutdown.bind(this, options);
586
if (type === NGHTTP2_SESSION_SERVER && options.graceful === true) {
587
// first send a shutdown notice
588
this[kHandle].shutdownNotice();
589
// then, on flip of the event loop, do the actual shutdown
- setImmediate(doShutdown.bind(this), options);
- doShutdown.call(this, options);
590
+ setImmediate(fn);
591
592
593
+ fn();
594
595
596
function finishSessionDestroy(socket) {
@@ -842,19 +845,19 @@ class Http2Session extends EventEmitter {
842
845
settings = Object.assign(Object.create(null), settings);
843
846
assertWithinRange('headerTableSize',
844
847
settings.headerTableSize,
- 0, 2 ** 32 - 1);
848
+ 0, kMaxInt);
849
assertWithinRange('initialWindowSize',
850
settings.initialWindowSize,
851
852
assertWithinRange('maxFrameSize',
853
settings.maxFrameSize,
- 16384, 2 ** 24 - 1);
854
+ 16384, kMaxFrameSize);
855
assertWithinRange('maxConcurrentStreams',
856
settings.maxConcurrentStreams,
857
0, kMaxStreams);
858
assertWithinRange('maxHeaderListSize',
859
settings.maxHeaderListSize,
860
861
if (settings.enablePush !== undefined &&
862
typeof settings.enablePush !== 'boolean') {
863
const err = new errors.TypeError('ERR_HTTP2_INVALID_SETTING_VALUE',
@@ -869,11 +872,12 @@ class Http2Session extends EventEmitter {
869
872
debug(`Http2Session ${sessionName(this[kType])}: sending settings`);
870
873
871
874
state.pendingAck++;
875
+ const fn = submitSettings.bind(this, settings);
876
if (state.connecting) {
- this.once('connect', submitSettings.bind(this, settings));
877
+ this.once('connect', fn);
878
879
- submitSettings.call(this, settings);
880
881
882
883
// Destroy the Http2Session
@@ -959,13 +963,14 @@ class Http2Session extends EventEmitter {
959
963
this.on('shutdown', callback);
960
964
961
965
966
+ const fn = submitShutdown.bind(this, options);
962
967
- this.once('connect', submitShutdown.bind(this, options));
968
969
970
971
972
debug(`Http2Session ${sessionName(type)}: sending shutdown`);
- submitShutdown.call(this, options);
973
974
975
976
_onTimeout() {
@@ -1366,7 +1371,7 @@ class Http2Stream extends Duplex {
1366
1371
rstStream(code = NGHTTP2_NO_ERROR) {
1367
1372
if (typeof code !== 'number')
1368
1373
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'code', 'number');
1369
- if (code < 0 || code > 2 ** 32 - 1)
1374
+ if (code < 0 || code > kMaxInt)
1370
1375
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'code');
1376
1377
const fn = submitRstStream.bind(this, code);
@@ -2360,19 +2365,19 @@ function getPackedSettings(settings) {
2360
2365
settings = settings || Object.create(null);
2361
2366
2362
2367
2363
2368
2364
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
@@ -2423,22 +2428,22 @@ function getUnpackedSettings(buf, options = {}) {
2423
2428
if (options != null && options.validate) {
2424
2429
2425
2430
2426
2431
2427
2432
assertWithinRange('enablePush',
2433
settings.enablePush,
2434
0, 1);
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
if (settings.enablePush !== undefined) {