|
23 | 23 |
|
24 | 24 | const { |
25 | 25 | NumberIsNaN, |
| 26 | + ObjectCreate, |
26 | 27 | ObjectKeys, |
27 | 28 | ObjectSetPrototypeOf, |
28 | 29 | ObjectValues, |
@@ -83,13 +84,13 @@ function Agent(options) { |
83 | 84 | this.defaultPort = 80; |
84 | 85 | this.protocol = 'http:'; |
85 | 86 |
|
86 | | - this.options = { ...options }; |
| 87 | + this.options = { __proto__: null, ...options }; |
87 | 88 |
|
88 | 89 | // Don't confuse net and make it think that we're connecting to a pipe |
89 | 90 | this.options.path = null; |
90 | | - this.requests = {}; |
91 | | - this.sockets = {}; |
92 | | - this.freeSockets = {}; |
| 91 | + this.requests = ObjectCreate(null); |
| 92 | + this.sockets = ObjectCreate(null); |
| 93 | + this.freeSockets = ObjectCreate(null); |
93 | 94 | this.keepAliveMsecs = this.options.keepAliveMsecs || 1000; |
94 | 95 | this.keepAlive = this.options.keepAlive || false; |
95 | 96 | this.maxSockets = this.options.maxSockets || Agent.defaultMaxSockets; |
@@ -227,13 +228,14 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */, |
227 | 228 | // Legacy API: addRequest(req, host, port, localAddress) |
228 | 229 | if (typeof options === 'string') { |
229 | 230 | options = { |
| 231 | + __proto__: null, |
230 | 232 | host: options, |
231 | 233 | port, |
232 | 234 | localAddress |
233 | 235 | }; |
234 | 236 | } |
235 | 237 |
|
236 | | - options = { ...options, ...this.options }; |
| 238 | + options = { __proto__: null, ...options, ...this.options }; |
237 | 239 | if (options.socketPath) |
238 | 240 | options.path = options.socketPath; |
239 | 241 |
|
@@ -294,7 +296,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */, |
294 | 296 | }; |
295 | 297 |
|
296 | 298 | Agent.prototype.createSocket = function createSocket(req, options, cb) { |
297 | | - options = { ...options, ...this.options }; |
| 299 | + options = { __proto__: null, ...options, ...this.options }; |
298 | 300 | if (options.socketPath) |
299 | 301 | options.path = options.socketPath; |
300 | 302 |
|
@@ -435,7 +437,7 @@ Agent.prototype.removeSocket = function removeSocket(s, options) { |
435 | 437 | // There might be older requests in a different origin, but |
436 | 438 | // if the origin which releases the socket has pending requests |
437 | 439 | // that will be prioritized. |
438 | | - for (const prop in this.requests) { |
| 440 | + for (const prop of ObjectKeys(this.requests)) { |
439 | 441 | // Check whether this specific origin is already at maxSockets |
440 | 442 | if (this.sockets[prop] && this.sockets[prop].length) break; |
441 | 443 | debug('removeSocket, have a request with different origin,' + |
|
0 commit comments