@@ -56,30 +56,30 @@ export class HttpClient implements Server.IHttpClient {
56
56
} ;
57
57
}
58
58
59
- const unmodifiedOptions = _ . clone ( options ) ;
59
+ const clonedOptions = _ . cloneDeep ( options ) ;
60
60
61
- if ( options . url ) {
62
- const urlParts = url . parse ( options . url ) ;
61
+ if ( clonedOptions . url ) {
62
+ const urlParts = url . parse ( clonedOptions . url ) ;
63
63
if ( urlParts . protocol ) {
64
- options . proto = urlParts . protocol . slice ( 0 , - 1 ) ;
64
+ clonedOptions . proto = urlParts . protocol . slice ( 0 , - 1 ) ;
65
65
}
66
- options . host = urlParts . hostname ;
67
- options . port = urlParts . port ;
68
- options . path = urlParts . path ;
66
+ clonedOptions . host = urlParts . hostname ;
67
+ clonedOptions . port = urlParts . port ;
68
+ clonedOptions . path = urlParts . path ;
69
69
}
70
70
71
- const requestProto = options . proto || "http" ;
72
- const body = options . body ;
73
- delete options . body ;
74
- let pipeTo = options . pipeTo ;
75
- delete options . pipeTo ;
71
+ const requestProto = clonedOptions . proto || "http" ;
72
+ const body = clonedOptions . body ;
73
+ delete clonedOptions . body ;
74
+ let pipeTo = options . pipeTo ; // Use the real stream because the _.cloneDeep can't clone the internal state of a stream.
75
+ delete clonedOptions . pipeTo ;
76
76
77
77
const cliProxySettings = await this . $proxyService . getCache ( ) ;
78
78
79
- options . headers = options . headers || { } ;
80
- const headers = options . headers ;
79
+ clonedOptions . headers = clonedOptions . headers || { } ;
80
+ const headers = clonedOptions . headers ;
81
81
82
- await this . useProxySettings ( proxySettings , cliProxySettings , options , headers , requestProto ) ;
82
+ await this . useProxySettings ( proxySettings , cliProxySettings , clonedOptions , headers , requestProto ) ;
83
83
84
84
if ( ! headers . Accept || headers . Accept . indexOf ( "application/json" ) < 0 ) {
85
85
if ( headers . Accept ) {
@@ -115,21 +115,21 @@ export class HttpClient implements Server.IHttpClient {
115
115
isResolved : ( ) => false
116
116
} ;
117
117
118
- if ( options . timeout ) {
118
+ clonedOptions . url = clonedOptions . url || `${ clonedOptions . proto } ://${ clonedOptions . host } ${ clonedOptions . path } ` ;
119
+ if ( clonedOptions . timeout ) {
119
120
timerId = setTimeout ( ( ) => {
120
- this . setResponseResult ( promiseActions , cleanupRequestData , { err : new Error ( `Request to ${ unmodifiedOptions . url } timed out.` ) } ) ;
121
- } , options . timeout ) ;
121
+ this . setResponseResult ( promiseActions , cleanupRequestData , { err : new Error ( `Request to ${ clonedOptions . url } timed out.` ) } ) ;
122
+ } , clonedOptions . timeout ) ;
122
123
cleanupRequestData . timers . push ( timerId ) ;
123
124
124
- delete options . timeout ;
125
+ delete clonedOptions . timeout ;
125
126
}
126
127
127
- options . url = options . url || `${ options . proto } ://${ options . host } ${ options . path } ` ;
128
- options . encoding = null ;
129
- options . followAllRedirects = true ;
128
+ clonedOptions . encoding = null ;
129
+ clonedOptions . followAllRedirects = true ;
130
130
131
- this . $logger . trace ( "httpRequest: %s" , util . inspect ( options ) ) ;
132
- const requestObj = request ( options ) ;
131
+ this . $logger . trace ( "httpRequest: %s" , util . inspect ( clonedOptions ) ) ;
132
+ const requestObj = request ( clonedOptions ) ;
133
133
cleanupRequestData . req = requestObj ;
134
134
135
135
requestObj
@@ -151,7 +151,7 @@ export class HttpClient implements Server.IHttpClient {
151
151
152
152
stuckRequestTimerId = setTimeout ( ( ) => {
153
153
this . setResponseResult ( promiseActions , cleanupRequestData , { err : new Error ( HttpClient . STUCK_REQUEST_ERROR_MESSAGE ) } ) ;
154
- } , options . timeout || HttpClient . STUCK_REQUEST_TIMEOUT ) ;
154
+ } , clonedOptions . timeout || HttpClient . STUCK_REQUEST_TIMEOUT ) ;
155
155
156
156
cleanupRequestData . timers . push ( stuckRequestTimerId ) ;
157
157
@@ -230,6 +230,7 @@ export class HttpClient implements Server.IHttpClient {
230
230
const response = await result ;
231
231
232
232
if ( helpers . isResponseRedirect ( response . response ) ) {
233
+ const unmodifiedOptions = _ . cloneDeep ( options ) ;
233
234
if ( response . response . statusCode === HttpStatusCodes . SEE_OTHER ) {
234
235
unmodifiedOptions . method = "GET" ;
235
236
}
0 commit comments