Add ability to disable the http agent (#1251)
This commit is contained in:
committed by
GitHub
parent
39cf023426
commit
1592c4d575
@ -38,12 +38,13 @@ class Connection {
|
||||
|
||||
if (typeof opts.agent === 'function') {
|
||||
this.agent = opts.agent()
|
||||
} else if (opts.agent === false) {
|
||||
this.agent = undefined
|
||||
} else {
|
||||
const keepAliveFalse = opts.agent && opts.agent.keepAlive === false
|
||||
const agentOptions = Object.assign({}, {
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: keepAliveFalse ? Infinity : 256,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo'
|
||||
}, opts.agent)
|
||||
@ -146,7 +147,9 @@ class Connection {
|
||||
if (this._openRequests > 0) {
|
||||
setTimeout(() => this.close(callback), 1000)
|
||||
} else {
|
||||
this.agent.destroy()
|
||||
if (this.agent !== undefined) {
|
||||
this.agent.destroy()
|
||||
}
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user