Skip to content

Commit a237f20

Browse files
authored
Update index.js
really not clone, reuse the originally agent by default, can specify one in retry strategy, even remove it via null value
1 parent 8c85f72 commit a237f20

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,16 @@ Request.prototype._tryUntilFail = function () {
131131
}
132132

133133
const originalAgent = this.options.agent;
134-
var mustRetry = await Promise.resolve(this.retryStrategy(err, response, body, _.cloneDeep(this.options)));
134+
delete this.options.agent;
135+
const clonedOptions = _.cloneDeep(this.options);
136+
this.options.agent = originalAgent;
137+
var mustRetry = await Promise.resolve(this.retryStrategy(err, response, body, clonedOptions));
135138
if (_.isObject(mustRetry) && _.has(mustRetry, 'mustRetry')) {
136139
if (_.isObject(mustRetry.options)) {
137140
this.options = mustRetry.options; //if retryStrategy supposes different request options for retry
138-
this.options.agent = originalAgent;
141+
if (originalAgent && typeof this.options.agent === 'undefined') {
142+
this.options.agent = originalAgent;
143+
}
139144
}
140145
mustRetry = mustRetry.mustRetry;
141146
}

0 commit comments

Comments
 (0)