Skip to content

createConnection option not work for https module #24543

Description

@yibopi

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);

Activity

  1. Trott commented on Nov 21, 2018

    @Trott
    Member

    @nodejs/http Seems like a legit bug in the https module?

  2. yibopi commented on Nov 21, 2018

    @yibopi
    Author

    @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?

  3. cjihrig commented on Nov 22, 2018

    @cjihrig
    Contributor

    but this only works when port = 80, not when port = 443
    Why createConnection only works for http, not https?

    I thinks it's because net.createConnection() and port 80 use HTTP, not HTTPS. The HTTPS agent's createConnection() is built around tls.connect().

  4. eecsreactive commented on Nov 27, 2018

    @eecsreactive

    @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!

  5. cjihrig commented on Nov 27, 2018

    @cjihrig
    Contributor

    @eecs441staff does createConnection: require('tls').connect not work for you?

  6. eecsreactive commented on Nov 27, 2018

    @eecsreactive

    @cjihrig It worked! Thanks.

  7. Trott commented on Dec 1, 2018

    @Trott
    Member

    Sounds to me like this can be closed, but comment and/or re-open if I've misunderstood.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions