-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: add highWaterMark option for connect
PR-URL: #32786 Fixes: #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>
- Loading branch information
1 parent
b50333e
commit 323da6f
Showing
5 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const tls = require('tls'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const pem = (n) => fixtures.readKey(`${n}.pem`); | ||
|
||
let clients = 0; | ||
|
||
const server = tls.createServer({ | ||
key: pem('agent1-key'), | ||
cert: pem('agent1-cert') | ||
}, common.mustCall(() => { | ||
if (--clients === 0) | ||
server.close(); | ||
}, 3)); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
clients++; | ||
const highBob = tls.connect({ | ||
port: server.address().port, | ||
rejectUnauthorized: false, | ||
highWaterMark: 128000, | ||
}, common.mustCall(() => { | ||
assert.strictEqual(highBob.readableHighWaterMark, 128000); | ||
highBob.end(); | ||
})); | ||
|
||
clients++; | ||
const defaultHighBob = tls.connect({ | ||
port: server.address().port, | ||
rejectUnauthorized: false, | ||
highWaterMark: undefined, | ||
}, common.mustCall(() => { | ||
assert.strictEqual(defaultHighBob.readableHighWaterMark, 16 * 1024); | ||
defaultHighBob.end(); | ||
})); | ||
|
||
clients++; | ||
const zeroHighBob = tls.connect({ | ||
port: server.address().port, | ||
rejectUnauthorized: false, | ||
highWaterMark: 0, | ||
}, common.mustCall(() => { | ||
assert.strictEqual(zeroHighBob.readableHighWaterMark, 0); | ||
zeroHighBob.end(); | ||
})); | ||
})); |