Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: improve http2 code a bit #23984

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions benchmark/http2/headers.js
Expand Up @@ -39,8 +39,7 @@ function main({ n, nheaders }) {

function doRequest(remaining) {
const req = client.request(headersObject);
req.end();
req.on('data', () => {});
req.resume();
req.on('end', () => {
if (remaining > 0) {
doRequest(remaining - 1);
Expand Down
6 changes: 3 additions & 3 deletions benchmark/http2/respond-with-fd.js
Expand Up @@ -7,9 +7,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'] });

Expand Down
6 changes: 3 additions & 3 deletions benchmark/http2/simple.js
Expand Up @@ -6,9 +6,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'] });

Expand Down
44 changes: 25 additions & 19 deletions lib/internal/http2/util.js
Expand Up @@ -430,14 +430,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:
Expand All @@ -459,26 +465,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 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 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];
Expand Down