Skip to content

Commit d55f90d

Browse files
darai0512MylesBorins
authored andcommitted
https: defines maxHeadersCount in the constructor
In Refs, http.Server's maxHeadersCount field was defined in the constructor to make hidden class stable and so on. Also in https.Server, we can use maxHeadersCount the same as http via connectionListener. So, defines it in the constructor and documentation. Refs: #9116 PR-URL: #20359 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent a5ba30b commit d55f90d

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

doc/api/https.md

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ See [`server.close()`][`http.close()`] from the HTTP module for details.
3636
Starts the HTTPS server listening for encrypted connections.
3737
This method is identical to [`server.listen()`][] from [`net.Server`][].
3838

39+
40+
### server.maxHeadersCount
41+
42+
- {number} **Default:** `2000`
43+
44+
See [`http.Server#maxHeadersCount`][].
45+
3946
### server.setTimeout([msecs][, callback])
4047
<!-- YAML
4148
added: v0.11.2
@@ -348,6 +355,7 @@ headers: max-age=0; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; p
348355
[`URL`]: url.html#url_the_whatwg_url_api
349356
[`http.Agent`]: http.html#http_class_http_agent
350357
[`http.Server#keepAliveTimeout`]: http.html#http_server_keepalivetimeout
358+
[`http.Server#maxHeadersCount`]: http.html#http_server_maxheaderscount
351359
[`http.Server#setTimeout()`]: http.html#http_server_settimeout_msecs_callback
352360
[`http.Server#timeout`]: http.html#http_server_timeout
353361
[`http.Server`]: http.html#http_class_http_server

lib/https.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function Server(opts, requestListener) {
7474

7575
this.timeout = 2 * 60 * 1000;
7676
this.keepAliveTimeout = 5000;
77+
this.maxHeadersCount = null;
7778
}
7879
inherits(Server, tls.Server);
7980

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use strict';
2+
const common = require('../common');
3+
const fixtures = require('../common/fixtures');
4+
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
8+
const assert = require('assert');
9+
const https = require('https');
10+
11+
const serverOptions = {
12+
key: fixtures.readKey('agent1-key.pem'),
13+
cert: fixtures.readKey('agent1-cert.pem')
14+
};
15+
16+
let requests = 0;
17+
let responses = 0;
18+
19+
const headers = {};
20+
const N = 2000;
21+
for (let i = 0; i < N; ++i) {
22+
headers[`key${i}`] = i;
23+
}
24+
25+
const maxAndExpected = [ // for server
26+
[50, 50],
27+
[1500, 1500],
28+
[0, N + 2] // Host and Connection
29+
];
30+
let max = maxAndExpected[requests][0];
31+
let expected = maxAndExpected[requests][1];
32+
33+
const server = https.createServer(serverOptions, common.mustCall((req, res) => {
34+
assert.strictEqual(Object.keys(req.headers).length, expected);
35+
if (++requests < maxAndExpected.length) {
36+
max = maxAndExpected[requests][0];
37+
expected = maxAndExpected[requests][1];
38+
server.maxHeadersCount = max;
39+
}
40+
res.writeHead(200, headers);
41+
res.end();
42+
}, 3));
43+
server.maxHeadersCount = max;
44+
45+
server.listen(0, common.mustCall(() => {
46+
const maxAndExpected = [ // for client
47+
[20, 20],
48+
[1200, 1200],
49+
[0, N + 3] // Connection, Date and Transfer-Encoding
50+
];
51+
const doRequest = common.mustCall(() => {
52+
const max = maxAndExpected[responses][0];
53+
const expected = maxAndExpected[responses][1];
54+
const req = https.request({
55+
port: server.address().port,
56+
headers: headers,
57+
rejectUnauthorized: false
58+
}, (res) => {
59+
assert.strictEqual(Object.keys(res.headers).length, expected);
60+
res.on('end', () => {
61+
if (++responses < maxAndExpected.length) {
62+
doRequest();
63+
} else {
64+
server.close();
65+
}
66+
});
67+
res.resume();
68+
});
69+
req.maxHeadersCount = max;
70+
req.end();
71+
}, 3);
72+
doRequest();
73+
}));

0 commit comments

Comments
 (0)