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 b095e35

Browse filesBrowse files
jasnellBethGriggs
authored andcommitted
http2: improve http2 code a bit
Multiple general improvements to http2 internals for readability and efficiency [This backport applied to v10.x cleanly but had several merge conflicts on v8.x.] PR-URL: #23984 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 07458ba commit b095e35
Copy full SHA for b095e35

File tree

Expand file treeCollapse file tree

5 files changed

+152
-135
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+152
-135
lines changed
Open diff view settings
Collapse file

‎benchmark/http2/headers.js‎

Copy file name to clipboardExpand all lines: benchmark/http2/headers.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ function main(conf) {
4242

4343
function doRequest(remaining) {
4444
const req = client.request(headersObject);
45-
req.end();
46-
req.on('data', () => {});
45+
req.resume();
4746
req.on('end', () => {
4847
if (remaining > 0) {
4948
doRequest(remaining - 1);
Collapse file

‎benchmark/http2/respond-with-fd.js‎

Copy file name to clipboardExpand all lines: benchmark/http2/respond-with-fd.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const fs = require('fs');
88
const file = path.join(path.resolve(__dirname, '../fixtures'), 'alice.html');
99

1010
const bench = common.createBenchmark(main, {
11-
requests: [100, 1000, 10000, 100000, 1000000],
12-
streams: [100, 200, 1000],
13-
clients: [1, 2],
11+
requests: [100, 1000, 5000],
12+
streams: [1, 10, 20, 40, 100, 200],
13+
clients: [2],
1414
benchmarker: ['h2load']
1515
}, { flags: ['--no-warnings', '--expose-http2'] });
1616

Collapse file

‎benchmark/http2/simple.js‎

Copy file name to clipboardExpand all lines: benchmark/http2/simple.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const fs = require('fs');
99
const file = path.join(path.resolve(__dirname, '../fixtures'), 'alice.html');
1010

1111
const bench = common.createBenchmark(main, {
12-
requests: [100, 1000, 10000, 100000],
13-
streams: [100, 200, 1000],
14-
clients: [1, 2],
12+
requests: [100, 1000, 5000],
13+
streams: [1, 10, 20, 40, 100, 200],
14+
clients: [2],
1515
benchmarker: ['h2load']
1616
}, { flags: ['--no-warnings', '--expose-http2'] });
1717

Collapse file

‎lib/internal/http2/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/util.js
+25-19Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,20 @@ function mapToHeaders(map,
408408
let count = 0;
409409
const keys = Object.keys(map);
410410
const singles = new Set();
411-
for (var i = 0; i < keys.length; i++) {
412-
let key = keys[i];
413-
let value = map[key];
411+
let i;
412+
let isArray;
413+
let key;
414+
let value;
415+
let isSingleValueHeader;
416+
let err;
417+
for (i = 0; i < keys.length; i++) {
418+
key = keys[i];
419+
value = map[key];
414420
if (value === undefined || key === '')
415421
continue;
416422
key = key.toLowerCase();
417-
const isSingleValueHeader = kSingleValueHeaders.has(key);
418-
let isArray = Array.isArray(value);
423+
isSingleValueHeader = kSingleValueHeaders.has(key);
424+
isArray = Array.isArray(value);
419425
if (isArray) {
420426
switch (value.length) {
421427
case 0:
@@ -437,26 +443,26 @@ function mapToHeaders(map,
437443
singles.add(key);
438444
}
439445
if (key[0] === ':') {
440-
const err = assertValuePseudoHeader(key);
446+
err = assertValuePseudoHeader(key);
441447
if (err !== undefined)
442448
return err;
443449
ret = `${key}\0${value}\0${ret}`;
444450
count++;
445-
} else {
446-
if (isIllegalConnectionSpecificHeader(key, value)) {
447-
return new errors.Error('ERR_HTTP2_INVALID_CONNECTION_HEADERS', key);
448-
}
449-
if (isArray) {
450-
for (var k = 0; k < value.length; k++) {
451-
const val = String(value[k]);
452-
ret += `${key}\0${val}\0`;
453-
}
454-
count += value.length;
455-
} else {
456-
ret += `${key}\0${value}\0`;
457-
count++;
451+
continue;
452+
}
453+
if (isIllegalConnectionSpecificHeader(key, value)) {
454+
return new errors.Error('ERR_HTTP2_INVALID_CONNECTION_HEADERS', key);
455+
}
456+
if (isArray) {
457+
for (var k = 0; k < value.length; k++) {
458+
const val = String(value[k]);
459+
ret += `${key}\0${val}\0`;
458460
}
461+
count += value.length;
462+
continue;
459463
}
464+
ret += `${key}\0${value}\0`;
465+
count++;
460466
}
461467

462468
return [ret, count];

0 commit comments

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