From db3239d499875757edf26d3840a0b4762ebff976 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Wed, 5 Jun 2019 00:17:24 +0300 Subject: [PATCH] Support 3-argument `.get()` methods Fixes https://github.com/TooTallNate/node-agent-base/issues/24 --- patch-core.js | 12 +++++++++++- test/test.js | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/patch-core.js b/patch-core.js index 47d26a7..5216c7b 100644 --- a/patch-core.js +++ b/patch-core.js @@ -30,7 +30,17 @@ https.request = (function(request) { * * Ref: https://github.com/nodejs/node/commit/5118f31 */ -https.get = function(options, cb) { +https.get = function (_url, _options, cb) { + let options; + if (typeof _url === 'string' && _options && typeof _options !== 'function') { + options = Object.assign({}, url.parse(_url), _options); + } else if (!_options && !cb) { + options = _url; + } else if (!cb) { + options = _url; + cb = _options; + } + const req = https.request(options, cb); req.end(); return req; diff --git a/test/test.js b/test/test.js index f569488..397ac42 100644 --- a/test/test.js +++ b/test/test.js @@ -542,6 +542,25 @@ describe('"https" module', function() { }); }); + it('should support the 3-argument `https.get()`', function(done) { + var agent = new Agent(function(req, opts, fn) { + assert.equal('google.com', opts.host); + assert.equal('/q', opts.pathname || opts.path); + assert.equal('881', opts.port); + assert.equal('bar', opts.foo); + done(); + }); + + https.get( + 'https://google.com:881/q', + { + host: 'google.com', + foo: 'bar', + agent: agent + } + ); + }); + it('should default to port 443', function(done) { var agent = new Agent(function(req, opts, fn) { assert.equal(true, opts.secureEndpoint);