@@ -56,30 +56,30 @@ export class HttpClient implements Server.IHttpClient {
5656 } ;
5757 }
5858
59- const unmodifiedOptions = _ . clone ( options ) ;
59+ const clonedOptions = _ . cloneDeep ( options ) ;
6060
61- if ( options . url ) {
62- const urlParts = url . parse ( options . url ) ;
61+ if ( clonedOptions . url ) {
62+ const urlParts = url . parse ( clonedOptions . url ) ;
6363 if ( urlParts . protocol ) {
64- options . proto = urlParts . protocol . slice ( 0 , - 1 ) ;
64+ clonedOptions . proto = urlParts . protocol . slice ( 0 , - 1 ) ;
6565 }
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 ;
6969 }
7070
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 ;
7676
7777 const cliProxySettings = await this . $proxyService . getCache ( ) ;
7878
79- options . headers = options . headers || { } ;
80- const headers = options . headers ;
79+ clonedOptions . headers = clonedOptions . headers || { } ;
80+ const headers = clonedOptions . headers ;
8181
82- await this . useProxySettings ( proxySettings , cliProxySettings , options , headers , requestProto ) ;
82+ await this . useProxySettings ( proxySettings , cliProxySettings , clonedOptions , headers , requestProto ) ;
8383
8484 if ( ! headers . Accept || headers . Accept . indexOf ( "application/json" ) < 0 ) {
8585 if ( headers . Accept ) {
@@ -115,21 +115,21 @@ export class HttpClient implements Server.IHttpClient {
115115 isResolved : ( ) => false
116116 } ;
117117
118- if ( options . timeout ) {
118+ clonedOptions . url = clonedOptions . url || `${ clonedOptions . proto } ://${ clonedOptions . host } ${ clonedOptions . path } ` ;
119+ if ( clonedOptions . timeout ) {
119120 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 ) ;
122123 cleanupRequestData . timers . push ( timerId ) ;
123124
124- delete options . timeout ;
125+ delete clonedOptions . timeout ;
125126 }
126127
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 ;
130130
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 ) ;
133133 cleanupRequestData . req = requestObj ;
134134
135135 requestObj
@@ -151,7 +151,7 @@ export class HttpClient implements Server.IHttpClient {
151151
152152 stuckRequestTimerId = setTimeout ( ( ) => {
153153 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 ) ;
155155
156156 cleanupRequestData . timers . push ( stuckRequestTimerId ) ;
157157
@@ -230,6 +230,7 @@ export class HttpClient implements Server.IHttpClient {
230230 const response = await result ;
231231
232232 if ( helpers . isResponseRedirect ( response . response ) ) {
233+ const unmodifiedOptions = _ . cloneDeep ( options ) ;
233234 if ( response . response . statusCode === HttpStatusCodes . SEE_OTHER ) {
234235 unmodifiedOptions . method = "GET" ;
235236 }
0 commit comments