Skip to content

Commit 4b6c653

Browse files
leeightBridgeAR
authored andcommitted
https: add missing localPort while create socket
In `_tls_wrap.js` while calling `socket.connect` the `localPort` was missing, restore it. PR-URL: nodejs#24554 Fixes: nodejs#24543 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 83fba1e commit 4b6c653

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/_tls_wrap.js

+1
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,7 @@ exports.connect = function connect(...args) {
12881288
host: options.host,
12891289
family: options.family,
12901290
localAddress: options.localAddress,
1291+
localPort: options.localPort,
12911292
lookup: options.lookup
12921293
};
12931294

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 https = require('https');
9+
const assert = require('assert');
10+
11+
{
12+
https.createServer({
13+
cert: fixtures.readKey('agent1-cert.pem'),
14+
key: fixtures.readKey('agent1-key.pem'),
15+
}, common.mustCall(function(req, res) {
16+
this.close();
17+
res.end();
18+
})).listen(0, common.localhostIPv4, common.mustCall(function() {
19+
const port = this.address().port;
20+
const req = https.get({
21+
host: common.localhostIPv4,
22+
pathname: '/',
23+
port,
24+
family: 4,
25+
localPort: 34567,
26+
rejectUnauthorized: false
27+
}, common.mustCall(() => {
28+
assert.strictEqual(req.socket.localPort, 34567);
29+
assert.strictEqual(req.socket.remotePort, port);
30+
}));
31+
}));
32+
}

0 commit comments

Comments
 (0)