From d4dc1a1a8c031cfc89955923e9b10242eb3013c6 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 9 May 2017 14:32:34 -0400 Subject: [PATCH] https: support agent construction without new Fixes: https://github.com/nodejs/node/issues/12918 Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Luigi Pinca --- lib/https.js | 3 +++ test/parallel/test-https-agent-constructor.js | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 test/parallel/test-https-agent-constructor.js diff --git a/lib/https.js b/lib/https.js index c44766bd6e6571..1ca546ac106248 100644 --- a/lib/https.js +++ b/lib/https.js @@ -119,6 +119,9 @@ function createConnection(port, host, options) { function Agent(options) { + if (!(this instanceof Agent)) + return new Agent(options); + http.Agent.call(this, options); this.defaultPort = 443; this.protocol = 'https:'; diff --git a/test/parallel/test-https-agent-constructor.js b/test/parallel/test-https-agent-constructor.js new file mode 100644 index 00000000000000..942ad07b4a3870 --- /dev/null +++ b/test/parallel/test-https-agent-constructor.js @@ -0,0 +1,7 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const https = require('https'); + +assert.doesNotThrow(() => { https.Agent(); }); +assert.ok(https.Agent() instanceof https.Agent);