Skip to content
Permalink
Browse files

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>
  • Loading branch information...
jasnell authored and BethGriggs committed Oct 30, 2018
1 parent 07458ba commit b095e35f1f45176d6d16d5b72a92f6b72a0ecbc6
Showing with 152 additions and 135 deletions.
  1. +1 −2 benchmark/http2/headers.js
  2. +3 −3 benchmark/http2/respond-with-fd.js
  3. +3 −3 benchmark/http2/simple.js
  4. +25 −19 lib/internal/http2/util.js
  5. +120 −108 src/node_http2.cc
@@ -42,8 +42,7 @@ function main(conf) {

function doRequest(remaining) {
const req = client.request(headersObject);
req.end();
req.on('data', () => {});
req.resume();
req.on('end', () => {
if (remaining > 0) {
doRequest(remaining - 1);
@@ -8,9 +8,9 @@ const fs = require('fs');
const file = path.join(path.resolve(__dirname, '../fixtures'), 'alice.html');

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

@@ -9,9 +9,9 @@ const fs = require('fs');
const file = path.join(path.resolve(__dirname, '../fixtures'), 'alice.html');

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

@@ -408,14 +408,20 @@ function mapToHeaders(map,
let count = 0;
const keys = Object.keys(map);
const singles = new Set();
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
let value = map[key];
let i;
let isArray;
let key;
let value;
let isSingleValueHeader;
let err;
for (i = 0; i < keys.length; i++) {
key = keys[i];
value = map[key];
if (value === undefined || key === '')
continue;
key = key.toLowerCase();
const isSingleValueHeader = kSingleValueHeaders.has(key);
let isArray = Array.isArray(value);
isSingleValueHeader = kSingleValueHeaders.has(key);
isArray = Array.isArray(value);
if (isArray) {
switch (value.length) {
case 0:
@@ -437,26 +443,26 @@ function mapToHeaders(map,
singles.add(key);
}
if (key[0] === ':') {
const err = assertValuePseudoHeader(key);
err = assertValuePseudoHeader(key);
if (err !== undefined)
return err;
ret = `${key}\0${value}\0${ret}`;
count++;
} else {
if (isIllegalConnectionSpecificHeader(key, value)) {
return new errors.Error('ERR_HTTP2_INVALID_CONNECTION_HEADERS', key);
}
if (isArray) {
for (var k = 0; k < value.length; k++) {
const val = String(value[k]);
ret += `${key}\0${val}\0`;
}
count += value.length;
} else {
ret += `${key}\0${value}\0`;
count++;
continue;
}
if (isIllegalConnectionSpecificHeader(key, value)) {
return new errors.Error('ERR_HTTP2_INVALID_CONNECTION_HEADERS', key);
}
if (isArray) {
for (var k = 0; k < value.length; k++) {
const val = String(value[k]);
ret += `${key}\0${val}\0`;
}
count += value.length;
continue;
}
ret += `${key}\0${value}\0`;
count++;
}

return [ret, count];

0 comments on commit b095e35

Please sign in to comment.
You can’t perform that action at this time.