From 489a158f771655c14b21d98779aa2ac6e8e1afb0 Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Tue, 1 Nov 2016 03:13:54 +0700 Subject: [PATCH] http: make `globalAgent` of `http` and `https` as overridable properties The `http.globalAgent` and `https.globalAgent` previously cannot be overridden directly by reassigning new a value. By exposing the `globalAgent`s of `http` and `https`, now it can be reassigned by: http.globalAgent = new MyAgent(); https.globalAgent = new MySecureAgent(); --- lib/http.js | 1 + lib/https.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index 6931a0e26c138a..bba0fec9fd8652 100644 --- a/lib/http.js +++ b/lib/http.js @@ -23,6 +23,7 @@ const client = require('_http_client'); const ClientRequest = exports.ClientRequest = client.ClientRequest; exports.request = function request(options, cb) { + options._defaultAgent = options._defaultAgent || exports.globalAgent || agent.globalAgent; return new ClientRequest(options, cb); }; diff --git a/lib/https.js b/lib/https.js index b8969b68452451..96ed03ba35e8fe 100644 --- a/lib/https.js +++ b/lib/https.js @@ -195,7 +195,7 @@ exports.request = function(options, cb) { } else { options = util._extend({}, options); } - options._defaultAgent = globalAgent; + options._defaultAgent = exports.globalAgent || globalAgent; return http.request(options, cb); };