Skip to content

Commit efb3c71

Browse files
rickyesBridgeAR
authored andcommitted
tls: add highWaterMark option for connect
PR-URL: #32786Fixes: #32781 Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
1 parent 3956ab5 commit efb3c71

5 files changed

Lines changed: 132 additions & 2 deletions

File tree

‎doc/api/https.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ Global instance of [`https.Agent`][] for all HTTPS client requests.
238238
<!-- YAML
239239
added: v0.3.6
240240
changes:
241+
- version: REPLACEME
242+
pr-url: https://github.com/nodejs/node/pull/32786
243+
description: The `highWaterMark` option is accepted now.
241244
- version: v10.9.0
242245
pr-url: https://github.com/nodejs/node/pull/21616
243246
description: The `url` parameter can now be passed along with a separate
@@ -263,7 +266,8 @@ Makes a request to a secure web server.
263266
The following additional `options` from [`tls.connect()`][] are also accepted:
264267
`ca`, `cert`, `ciphers`, `clientCertEngine`, `crl`, `dhparam`, `ecdhCurve`,
265268
`honorCipherOrder`, `key`, `passphrase`, `pfx`, `rejectUnauthorized`,
266-
`secureOptions`, `secureProtocol`, `servername`, `sessionIdContext`.
269+
`secureOptions`, `secureProtocol`, `servername`, `sessionIdContext`,
270+
`highWaterMark`.
267271

268272
`options` can be an object, a string, or a [`URL`][] object. If `options` is a
269273
string, it is automatically parsed with [`new URL()`][]. If it is a [`URL`][]

‎doc/api/tls.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,9 @@ being issued by trusted CA (`options.ca`).
12741274
<!-- YAML
12751275
added: v0.11.3
12761276
changes:
1277+
- version: REPLACEME
1278+
pr-url: https://github.com/nodejs/node/pull/32786
1279+
description: The `highWaterMark` option is accepted now.
12771280
- version: v13.6.0
12781281
pr-url: https://github.com/nodejs/node/pull/23188
12791282
description: The `pskCallback` option is now supported.
@@ -1370,6 +1373,8 @@ changes:
13701373
TLS connection. When a server offers a DH parameter with a size less
13711374
than `minDHSize`, the TLS connection is destroyed and an error is thrown.
13721375
**Default:**`1024`.
1376+
*`highWaterMark`: {number} Consistent with the readable stream `highWaterMark` parameter.
1377+
**Default:**`16 * 1024`.
13731378
*`secureContext`: TLS context object created with
13741379
[`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one
13751380
will be created by passing the entire `options` object to

‎lib/_tls_wrap.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ function TLSSocket(socket, opts) {
500500
pauseOnCreate: tlsOptions.pauseOnConnect,
501501
// The readable flag is only needed if pauseOnCreate will be handled.
502502
readable: tlsOptions.pauseOnConnect,
503-
writable: false
503+
writable: false,
504+
highWaterMark: tlsOptions.highWaterMark
504505
});
505506

506507
// Proxy for API compatibility
@@ -1584,6 +1585,7 @@ exports.connect = function connect(...args) {
15841585
requestOCSP: options.requestOCSP,
15851586
enableTrace: options.enableTrace,
15861587
pskCallback: options.pskCallback,
1588+
highWaterMark: options.highWaterMark,
15871589
});
15881590

15891591
tlssock[kConnectOptions]=options;

‎test/parallel/test-https-hwm.js‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
3+
// Test https highWaterMark
4+
5+
constcommon=require('../common');
6+
if(!common.hasCrypto)
7+
common.skip('missing crypto');
8+
9+
constassert=require('assert');
10+
consthttps=require('https');
11+
constfixtures=require('../common/fixtures');
12+
13+
letcounter=0;
14+
15+
functionloadCallback(highWaterMark){
16+
returncommon.mustCall(function(res){
17+
assert.strictEqual(highWaterMark,res.readableHighWaterMark);
18+
counter--;
19+
console.log('back from https request. ',
20+
`highWaterMark = ${res.readableHighWaterMark}`);
21+
if(counter===0){
22+
httpsServer.close();
23+
console.log('ok');
24+
}
25+
res.resume();
26+
});
27+
}
28+
29+
// create server
30+
consthttpsServer=https.createServer({
31+
key: fixtures.readKey('agent1-key.pem'),
32+
cert: fixtures.readKey('agent1-cert.pem')
33+
},common.mustCall(function(req,res){
34+
res.writeHead(200,{});
35+
res.end('ok');
36+
},3)).listen(0,common.mustCall(function(err){
37+
console.log(`test https server listening on port ${this.address().port}`);
38+
assert.ifError(err);
39+
40+
https.request({
41+
method: 'GET',
42+
path: `/${counter++}`,
43+
host: 'localhost',
44+
port: this.address().port,
45+
rejectUnauthorized: false,
46+
highWaterMark: 128000,
47+
},loadCallback(128000)).on('error',common.mustNotCall()).end();
48+
49+
https.request({
50+
method: 'GET',
51+
path: `/${counter++}`,
52+
host: 'localhost',
53+
port: this.address().port,
54+
rejectUnauthorized: false,
55+
highWaterMark: 0,
56+
},loadCallback(0)).on('error',common.mustNotCall()).end();
57+
58+
https.request({
59+
method: 'GET',
60+
path: `/${counter++}`,
61+
host: 'localhost',
62+
port: this.address().port,
63+
rejectUnauthorized: false,
64+
highWaterMark: undefined,
65+
},loadCallback(16*1024)).on('error',common.mustNotCall()).end();
66+
}));
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
if(!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
constassert=require('assert');
8+
consttls=require('tls');
9+
constfixtures=require('../common/fixtures');
10+
11+
constpem=(n)=>fixtures.readKey(`${n}.pem`);
12+
13+
letclients=0;
14+
15+
constserver=tls.createServer({
16+
key: pem('agent1-key'),
17+
cert: pem('agent1-cert')
18+
},common.mustCall(()=>{
19+
if(--clients===0)
20+
server.close();
21+
},3));
22+
23+
server.listen(0,common.mustCall(()=>{
24+
clients++;
25+
consthighBob=tls.connect({
26+
port: server.address().port,
27+
rejectUnauthorized: false,
28+
highWaterMark: 128000,
29+
},common.mustCall(()=>{
30+
assert.strictEqual(highBob.readableHighWaterMark,128000);
31+
highBob.end();
32+
}));
33+
34+
clients++;
35+
constdefaultHighBob=tls.connect({
36+
port: server.address().port,
37+
rejectUnauthorized: false,
38+
highWaterMark: undefined,
39+
},common.mustCall(()=>{
40+
assert.strictEqual(defaultHighBob.readableHighWaterMark,16*1024);
41+
defaultHighBob.end();
42+
}));
43+
44+
clients++;
45+
constzeroHighBob=tls.connect({
46+
port: server.address().port,
47+
rejectUnauthorized: false,
48+
highWaterMark: 0,
49+
},common.mustCall(()=>{
50+
assert.strictEqual(zeroHighBob.readableHighWaterMark,0);
51+
zeroHighBob.end();
52+
}));
53+
}));

0 commit comments

Comments
 (0)