From 63e2d78e76d2af1e584b91f013011db8034fae2e Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Sun, 28 May 2023 17:20:32 -0300 Subject: [node:net] fix createConnection options passing (#3101) * fixup createConnection * fix comment * fixup comment * also fix it on tls --- src/bun.js/net.exports.js | 16 +++++----------- src/bun.js/node-tls.exports.js | 17 +++++------------ 2 files changed, 10 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/bun.js/net.exports.js b/src/bun.js/net.exports.js index 14c30effc..3d15eed2b 100644 --- a/src/bun.js/net.exports.js +++ b/src/bun.js/net.exports.js @@ -531,18 +531,12 @@ const Socket = (function (InternalSocket) { ); function createConnection(port, host, connectListener) { - if (typeof host == "function") { - connectListener = host; - host = undefined; + if (typeof port === "object") { + // port is option pass Socket options and let connect handle connection options + return new Socket(port).connect(port, host, connectListener); } - var options = - typeof port == "object" - ? port - : { - host: host, - port: port, - }; - return new Socket(options).connect(options, connectListener); + // port is path or host, let connect handle this + return new Socket().connect(port, host, connectListener); } const connect = createConnection; diff --git a/src/bun.js/node-tls.exports.js b/src/bun.js/node-tls.exports.js index cbbab8e4e..d54b79089 100644 --- a/src/bun.js/node-tls.exports.js +++ b/src/bun.js/node-tls.exports.js @@ -294,19 +294,12 @@ export const CLIENT_RENEG_LIMIT = 3, DEFAULT_MIN_VERSION = "TLSv1.2", DEFAULT_MAX_VERSION = "TLSv1.3", createConnection = (port, host, connectListener) => { - if (typeof host == "function") { - connectListener = host; - host = undefined; + if (typeof port === "object") { + // port is option pass Socket options and let connect handle connection options + return new TLSSocket(port).connect(port, host, connectListener); } - var options = - typeof port == "object" - ? port - : { - host: host, - port: port, - }; - - return new TLSSocket(options).connect(options, connectListener); + // port is path or host, let connect handle this + return new TLSSocket().connect(port, host, connectListener); }, connect = createConnection; -- cgit v1.2.3