@@ -25,6 +25,18 @@ function defaultPromiseFactory(resolver) {
2525 return when . promise ( resolver ) ;
2626}
2727
28+ function _cloneOptions ( options ) {
29+ const cloned = { } ;
30+ for ( let key in options ) {
31+ if ( key === 'agent' ) {
32+ cloned [ key ] = options [ key ] ;
33+ } else {
34+ cloned [ key ] = _ . cloneDeep ( options [ key ] ) ;
35+ }
36+ }
37+ return cloned ;
38+ }
39+
2840/**
2941 * It calls the promiseFactory function passing it the resolver for the promise
3042 *
@@ -130,17 +142,10 @@ Request.prototype._tryUntilFail = function () {
130142 err . attempts = this . attempts ;
131143 }
132144
133- const originalAgent = this . options . agent ;
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 ) ) ;
145+ var mustRetry = await Promise . resolve ( this . retryStrategy ( err , response , body , _cloneOptions ( this . options ) ) ) ;
138146 if ( _ . isObject ( mustRetry ) && _ . has ( mustRetry , 'mustRetry' ) ) {
139147 if ( _ . isObject ( mustRetry . options ) ) {
140148 this . options = mustRetry . options ; //if retryStrategy supposes different request options for retry
141- if ( originalAgent && typeof this . options . agent === 'undefined' ) {
142- this . options . agent = originalAgent ;
143- }
144149 }
145150 mustRetry = mustRetry . mustRetry ;
146151 }
0 commit comments