Skip to content

Commit c937e38

Browse files
committed
https: add missing localPort while create socket
In `_tls_wrap.js` while calling `socket.connect` the `localPort` was missing, restore it. Fix: #24543
1 parent e214069 commit c937e38

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/_tls_wrap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,7 @@ exports.connect = function connect(...args) {
12481248
host: options.host,
12491249
family: options.family,
12501250
localAddress: options.localAddress,
1251+
localPort: options.localPort,
12511252
lookup: options.lookup
12521253
};
12531254
socket.connect(connectOpt, socket._start);
Lines changed: 32 additions & 0 deletions
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)