@@ -33,30 +33,36 @@ function requestInterceptor (options: IOldReqOptions | AxiosRequestConfig): Axio
33
33
url : ( options . url as string ) || '' ,
34
34
headers : options . headers || { }
35
35
}
36
-
36
+ // user request config proxy
37
37
if ( options . proxy ) {
38
- if ( typeof options . proxy === 'string' ) {
38
+ let proxyOptions = options . proxy
39
+ if ( typeof proxyOptions === 'string' ) {
39
40
try {
40
- const proxyOptions = new URL ( options . proxy )
41
- if ( options . url ?. startsWith ( 'https://' ) ) {
42
- opt . proxy = false
43
- opt . httpsAgent = tunnel . httpsOverHttp ( {
44
- proxy : {
45
- host : proxyOptions . hostname ,
46
- port : parseInt ( proxyOptions . port , 10 )
47
- }
48
- } )
49
- } else {
50
- opt . proxy = {
51
- host : proxyOptions . hostname ,
52
- port : parseInt ( proxyOptions . port , 10 ) ,
53
- protocol : 'http'
54
- }
55
- }
41
+ proxyOptions = new URL ( options . proxy )
56
42
} catch ( e ) {
43
+ proxyOptions = false
44
+ opt . proxy = false
45
+ console . error ( e )
57
46
}
58
47
__isOldOptions = true
59
48
}
49
+ if ( proxyOptions ) {
50
+ if ( options . url ?. startsWith ( 'https://' ) ) {
51
+ opt . proxy = false
52
+ opt . httpsAgent = tunnel . httpsOverHttp ( {
53
+ proxy : {
54
+ host : proxyOptions ?. hostname ,
55
+ port : parseInt ( proxyOptions ?. port , 10 )
56
+ }
57
+ } )
58
+ } else {
59
+ opt . proxy = {
60
+ host : proxyOptions . hostname ,
61
+ port : parseInt ( proxyOptions . port , 10 ) ,
62
+ protocol : 'http'
63
+ }
64
+ }
65
+ }
60
66
}
61
67
if ( 'formData' in options ) {
62
68
const form = new FormData ( )
@@ -172,7 +178,19 @@ export class Request implements IRequest {
172
178
this . options . headers = options . headers || { }
173
179
this . options . maxBodyLength = Infinity
174
180
this . options . maxContentLength = Infinity
175
- this . options . httpsAgent = httpsAgent
181
+ if ( this . options . proxy && options . url ?. startsWith ( 'https://' ) ) {
182
+ this . options . httpsAgent = tunnel . httpsOverHttp ( {
183
+ proxy : {
184
+ host : this . options . proxy . host ,
185
+ port : this . options . proxy . port
186
+ }
187
+ } )
188
+ this . options . proxy = false
189
+ } else {
190
+ this . options . httpsAgent = httpsAgent
191
+ }
192
+ // !NOTICE this.options !== options
193
+ // this.options is the default options
176
194
const instance = axios . create ( this . options )
177
195
instance . interceptors . response . use ( responseInterceptor , responseErrorHandler )
178
196
0 commit comments