Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bdcbe81

Browse filesBrowse files
jasnellMylesBorins
authored andcommitted
http2: general cleanups
PR-URL: #17328 Fixes: #15303 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Sebastiaan Deckers <sebdeckers83@gmail.com>
1 parent c57cd9b commit bdcbe81
Copy full SHA for bdcbe81

File tree

Expand file treeCollapse file tree

1 file changed

+27
-22
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+27
-22
lines changed
Open diff view settings
Collapse file

‎lib/internal/http2/core.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/core.js
+27-22Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const { _connectionListener: httpConnectionListener } = require('http');
2828
const { createPromise, promiseResolve } = process.binding('util');
2929
const debug = util.debuglog('http2');
3030

31+
const kMaxFrameSize = (2 ** 24) - 1;
32+
const kMaxInt = (2 ** 32) - 1;
3133
const kMaxStreams = (2 ** 31) - 1;
3234

3335
const {
@@ -330,9 +332,9 @@ function emitGoaway(self, code, lastStreamID, buf) {
330332
return;
331333
if (!state.shuttingDown && !state.shutdown) {
332334
self.shutdown({}, self.destroy.bind(self));
333-
} else {
334-
self.destroy();
335+
return;
335336
}
337+
self.destroy();
336338
}
337339

338340
// Called by the native layer when a goaway frame has been received
@@ -580,14 +582,15 @@ function doShutdown(options) {
580582
function submitShutdown(options) {
581583
const type = this[kType];
582584
debug(`Http2Session ${sessionName(type)}: submitting shutdown request`);
585+
const fn = doShutdown.bind(this, options);
583586
if (type === NGHTTP2_SESSION_SERVER && options.graceful === true) {
584587
// first send a shutdown notice
585588
this[kHandle].shutdownNotice();
586589
// then, on flip of the event loop, do the actual shutdown
587-
setImmediate(doShutdown.bind(this), options);
588-
} else {
589-
doShutdown.call(this, options);
590+
setImmediate(fn);
591+
return;
590592
}
593+
fn();
591594
}
592595

593596
function finishSessionDestroy(socket) {
@@ -842,19 +845,19 @@ class Http2Session extends EventEmitter {
842845
settings = Object.assign(Object.create(null), settings);
843846
assertWithinRange('headerTableSize',
844847
settings.headerTableSize,
845-
0, 2 ** 32 - 1);
848+
0, kMaxInt);
846849
assertWithinRange('initialWindowSize',
847850
settings.initialWindowSize,
848-
0, 2 ** 32 - 1);
851+
0, kMaxInt);
849852
assertWithinRange('maxFrameSize',
850853
settings.maxFrameSize,
851-
16384, 2 ** 24 - 1);
854+
16384, kMaxFrameSize);
852855
assertWithinRange('maxConcurrentStreams',
853856
settings.maxConcurrentStreams,
854857
0, kMaxStreams);
855858
assertWithinRange('maxHeaderListSize',
856859
settings.maxHeaderListSize,
857-
0, 2 ** 32 - 1);
860+
0, kMaxInt);
858861
if (settings.enablePush !== undefined &&
859862
typeof settings.enablePush !== 'boolean') {
860863
const err = new errors.TypeError('ERR_HTTP2_INVALID_SETTING_VALUE',
@@ -869,11 +872,12 @@ class Http2Session extends EventEmitter {
869872
debug(`Http2Session ${sessionName(this[kType])}: sending settings`);
870873

871874
state.pendingAck++;
875+
const fn = submitSettings.bind(this, settings);
872876
if (state.connecting) {
873-
this.once('connect', submitSettings.bind(this, settings));
877+
this.once('connect', fn);
874878
return;
875879
}
876-
submitSettings.call(this, settings);
880+
fn();
877881
}
878882

879883
// Destroy the Http2Session
@@ -959,13 +963,14 @@ class Http2Session extends EventEmitter {
959963
this.on('shutdown', callback);
960964
}
961965

966+
const fn = submitShutdown.bind(this, options);
962967
if (state.connecting) {
963-
this.once('connect', submitShutdown.bind(this, options));
968+
this.once('connect', fn);
964969
return;
965970
}
966971

967972
debug(`Http2Session ${sessionName(type)}: sending shutdown`);
968-
submitShutdown.call(this, options);
973+
fn();
969974
}
970975

971976
_onTimeout() {
@@ -1366,7 +1371,7 @@ class Http2Stream extends Duplex {
13661371
rstStream(code = NGHTTP2_NO_ERROR) {
13671372
if (typeof code !== 'number')
13681373
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'code', 'number');
1369-
if (code < 0 || code > 2 ** 32 - 1)
1374+
if (code < 0 || code > kMaxInt)
13701375
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'code');
13711376

13721377
const fn = submitRstStream.bind(this, code);
@@ -2360,19 +2365,19 @@ function getPackedSettings(settings) {
23602365
settings = settings || Object.create(null);
23612366
assertWithinRange('headerTableSize',
23622367
settings.headerTableSize,
2363-
0, 2 ** 32 - 1);
2368+
0, kMaxInt);
23642369
assertWithinRange('initialWindowSize',
23652370
settings.initialWindowSize,
2366-
0, 2 ** 32 - 1);
2371+
0, kMaxInt);
23672372
assertWithinRange('maxFrameSize',
23682373
settings.maxFrameSize,
2369-
16384, 2 ** 24 - 1);
2374+
16384, kMaxFrameSize);
23702375
assertWithinRange('maxConcurrentStreams',
23712376
settings.maxConcurrentStreams,
23722377
0, kMaxStreams);
23732378
assertWithinRange('maxHeaderListSize',
23742379
settings.maxHeaderListSize,
2375-
0, 2 ** 32 - 1);
2380+
0, kMaxInt);
23762381
if (settings.enablePush !== undefined &&
23772382
typeof settings.enablePush !== 'boolean') {
23782383
const err = new errors.TypeError('ERR_HTTP2_INVALID_SETTING_VALUE',
@@ -2423,22 +2428,22 @@ function getUnpackedSettings(buf, options = {}) {
24232428
if (options != null && options.validate) {
24242429
assertWithinRange('headerTableSize',
24252430
settings.headerTableSize,
2426-
0, 2 ** 32 - 1);
2431+
0, kMaxInt);
24272432
assertWithinRange('enablePush',
24282433
settings.enablePush,
24292434
0, 1);
24302435
assertWithinRange('initialWindowSize',
24312436
settings.initialWindowSize,
2432-
0, 2 ** 32 - 1);
2437+
0, kMaxInt);
24332438
assertWithinRange('maxFrameSize',
24342439
settings.maxFrameSize,
2435-
16384, 2 ** 24 - 1);
2440+
16384, kMaxFrameSize);
24362441
assertWithinRange('maxConcurrentStreams',
24372442
settings.maxConcurrentStreams,
24382443
0, kMaxStreams);
24392444
assertWithinRange('maxHeaderListSize',
24402445
settings.maxHeaderListSize,
2441-
0, 2 ** 32 - 1);
2446+
0, kMaxInt);
24422447
}
24432448

24442449
if (settings.enablePush !== undefined) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.