Skip to content

Commit 4b4dba5

Browse files
committed
https: make https.globalAgent overridable also under ECMAScript Modules
Under ECMAScript modules when you do "import * as https from 'https'" you get a new object with properties copied from https module exports. So if this is a regular data property, you will just override a copy, but if this would be a accessor property, we can still access the actual https.globalAgent. Refs: nodejs#25170, nodejs#9386
1 parent 7196946 commit 4b4dba5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/https.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ Agent.prototype._evictSession = function _evictSession(key) {
350350
delete this._sessionCache.map[key];
351351
};
352352

353-
const globalAgent = new Agent({ keepAlive: true, scheduling: 'lifo', timeout: 5000 });
353+
let globalAgent = new Agent({ keepAlive: true, scheduling: 'lifo', timeout: 5000 });
354354

355355
/**
356356
* Makes a request to a secure web server.
@@ -415,9 +415,21 @@ function get(input, options, cb) {
415415

416416
module.exports = {
417417
Agent,
418-
globalAgent,
419418
Server,
420419
createServer,
421420
get,
422421
request,
423422
};
423+
424+
// make https.globalAgent overridable also under ECMAScript Modules
425+
ObjectDefineProperty(module.exports, 'globalAgent', {
426+
__proto__: null,
427+
configurable: true,
428+
enumerable: true,
429+
get() {
430+
return globalAgent;
431+
},
432+
set(value) {
433+
globalAgent = value;
434+
},
435+
});

0 commit comments

Comments
 (0)