You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
createConnection option not work for https module #24543
Version: v10.13.0
Platform: Linux 4.15.0-39-generic x86_64
I am trying to use the createConnection option in the https module to set the client local port (localPort=34567 in the example below), but this only works when port = 80, not when port = 443. Following is the code I used to test. Does it mean that https module cannot set a custom socket for https in this way? Thanks.
const https = require('https');
const url = require('url');
var req = https.get({
host: 'google.com',
pathname: '/',
port: 443, // works when equal to 80, but not 443
family: 4,
localPort: 34567,
createConnection: require('net').createConnection
}, function(res) {
console.log('localPort:', req.socket.localPort, "remotePort:", req.socket.remotePort);
});
req.on('error', console.error);
@leeight , thanks.
Adding localPort does enforce the local port, but it cannot be used together with the createConnection option. Why createConnection only works for http, not https?
@cjihrig creatConnection is useful for opening a custom socket. Can this feature be added for HTTPS? Or is there a way to customize socket for HTTPS? Thanks!
Activity
Trott commentedon Nov 21, 2018
@nodejs/http Seems like a legit bug in the
httpsmodule?yibopi commentedon Nov 21, 2018
@leeight , thanks.
Adding localPort does enforce the local port, but it cannot be used together with the createConnection option. Why createConnection only works for http, not https?
cjihrig commentedon Nov 22, 2018
I thinks it's because
net.createConnection()and port 80 use HTTP, not HTTPS. The HTTPS agent'screateConnection()is built aroundtls.connect().https: add missing localPort while create socket
eecsreactive commentedon Nov 27, 2018
@cjihrig creatConnection is useful for opening a custom socket. Can this feature be added for HTTPS? Or is there a way to customize socket for HTTPS? Thanks!
cjihrig commentedon Nov 27, 2018
@eecs441staff does
createConnection: require('tls').connectnot work for you?eecsreactive commentedon Nov 27, 2018
@cjihrig It worked! Thanks.
Trott commentedon Dec 1, 2018
Sounds to me like this can be closed, but comment and/or re-open if I've misunderstood.
https: add missing localPort while create socket
https: add missing localPort while create socket
https: add missing localPort while create socket