lib: support overriding http\s.globalAgent
Overriding require('http').globalAgent
and require('https').globalAgent
is now respected by consequent requests.
In order to achieve that, the following changes were made:
-
http
:module.exports.globalAgent
is now defined throughObject.defineProperty
. Its getter and setter return \ setrequire('_http_agent').globalAgent
. -
https
: the httpsglobalAgent
is not the same as_http_agent
, and is defined inhttps
module itself. Therefore, the fix here was to simply usemodule.exports.globalAgent
to support mutation. -
test/parallel
: according tests were added for bothhttp
andhttps
, where in both we create a server, set the default agent to a newly created instance and make a request to that server. We then assert that the given instance was actually used by inspecting its sockets property.
Fixes: https://github.com/nodejs/node/issues/23281
On a side note, this is my first contribution to the project. Would appreciate feedback :)
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines