tls: connect supports highWaterMark option by rickyes · Pull Request #32786 · nodejs/node · GitHub
Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/api/https.md
5 changes: 5 additions & 0 deletions doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,9 @@ being issued by trusted CA (`options.ca`).
<!-- YAML
added: v0.11.3
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/32786
description: The `highWaterMark` option is accepted now.
- version: v13.6.0
pr-url: https://github.com/nodejs/node/pull/23188
description: The `pskCallback` option is now supported.
Expand Down Expand Up @@ -1370,6 +1373,8 @@ changes:
TLS connection. When a server offers a DH parameter with a size less
than `minDHSize`, the TLS connection is destroyed and an error is thrown.
**Default:** `1024`.
* `highWaterMark`: {number} Consistent with the readable stream `highWaterMark` parameter.
**Default:** `16 * 1024`.
* `secureContext`: TLS context object created with
[`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one
will be created by passing the entire `options` object to
Expand Down
4 changes: 3 additions & 1 deletion lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ function TLSSocket(socket, opts) {
handle: this._wrapHandle(wrap),
allowHalfOpen: socket ? socket.allowHalfOpen : tlsOptions.allowHalfOpen,
pauseOnCreate: tlsOptions.pauseOnConnect,
manualStart: true
manualStart: true,
highWaterMark: tlsOptions.highWaterMark,
});

// Proxy for API compatibility
Expand Down Expand Up @@ -1582,6 +1583,7 @@ exports.connect = function connect(...args) {
requestOCSP: options.requestOCSP,
enableTrace: options.enableTrace,
pskCallback: options.pskCallback,
highWaterMark: options.highWaterMark,
});

tlssock[kConnectOptions] = options;
Expand Down
66 changes: 66 additions & 0 deletions test/parallel/test-https-hwm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict';

// Test https highWaterMark

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('assert');
const https = require('https');
const fixtures = require('../common/fixtures');

let counter = 0;

function loadCallback(highWaterMark) {
return common.mustCall(function(res) {
assert.strictEqual(highWaterMark, res.readableHighWaterMark);
counter--;
console.log('back from https request. ',
`highWaterMark = ${res.readableHighWaterMark}`);
if (counter === 0) {
httpsServer.close();
console.log('ok');
}
res.resume();
});
}

// create server
const httpsServer = https.createServer({
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem')
}, common.mustCall(function(req, res) {
res.writeHead(200, {});
res.end('ok');
}, 3)).listen(0, common.mustCall(function(err) {
console.log(`test https server listening on port ${this.address().port}`);
assert.ifError(err);

https.request({
method: 'GET',
path: `/${counter++}`,
host: 'localhost',
port: this.address().port,
rejectUnauthorized: false,
highWaterMark: 128000,
}, loadCallback(128000)).on('error', common.mustNotCall()).end();

https.request({
method: 'GET',
path: `/${counter++}`,
host: 'localhost',
port: this.address().port,
rejectUnauthorized: false,
highWaterMark: 0,
}, loadCallback(0)).on('error', common.mustNotCall()).end();

https.request({
method: 'GET',
path: `/${counter++}`,
host: 'localhost',
port: this.address().port,
rejectUnauthorized: false,
highWaterMark: undefined,
}, loadCallback(16 * 1024)).on('error', common.mustNotCall()).end();
}));
53 changes: 53 additions & 0 deletions test/parallel/test-tls-connect-hwm-option.js