Skip to content

Commit

Permalink
https: make https.globalAgent overridable also under ECMAScript Modules
Browse files Browse the repository at this point in the history
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: #25170, #9386
  • Loading branch information
whut committed Jul 17, 2023
1 parent 7196946 commit 4b4dba5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ Agent.prototype._evictSession = function _evictSession(key) {
delete this._sessionCache.map[key];
};

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

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

module.exports = {
Agent,
globalAgent,
Server,
createServer,
get,
request,
};

// make https.globalAgent overridable also under ECMAScript Modules
ObjectDefineProperty(module.exports, 'globalAgent', {
__proto__: null,
configurable: true,
enumerable: true,
get() {
return globalAgent;
},
set(value) {
globalAgent = value;
},
});

0 comments on commit 4b4dba5

Please sign in to comment.