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 <matteo.collina@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent a5ba30b commit d55f90d

3 files changed

Lines changed: 82 additions & 0 deletions

File tree

‎doc/api/https.md‎

Lines changed: 8 additions & 0 deletions
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‎

Lines changed: 1 addition & 0 deletions
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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
constfixtures=require('../common/fixtures');
4+
5+
if(!common.hasCrypto)
6+
common.skip('missing crypto');
7+
8+
constassert=require('assert');
9+
consthttps=require('https');
10+
11+
constserverOptions={
12+
key: fixtures.readKey('agent1-key.pem'),
13+
cert: fixtures.readKey('agent1-cert.pem')
14+
};
15+
16+
letrequests=0;
17+
letresponses=0;
18+
19+
constheaders={};
20+
constN=2000;
21+
for(leti=0;i<N;++i){
22+
headers[`key${i}`]=i;
23+
}
24+
25+
constmaxAndExpected=[// for server
26+
[50,50],
27+
[1500,1500],
28+
[0,N+2]// Host and Connection
29+
];
30+
letmax=maxAndExpected[requests][0];
31+
letexpected=maxAndExpected[requests][1];
32+
33+
constserver=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+
constmaxAndExpected=[// for client
47+
[20,20],
48+
[1200,1200],
49+
[0,N+3]// Connection, Date and Transfer-Encoding
50+
];
51+
constdoRequest=common.mustCall(()=>{
52+
constmax=maxAndExpected[responses][0];
53+
constexpected=maxAndExpected[responses][1];
54+
constreq=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)