@@ -159,21 +159,21 @@ func TestDownloader_CreateDirectBatch(t *testing.T) {
159
159
160
160
func TestDownloader_CreateWithProxy (t * testing.T ) {
161
161
// No proxy
162
- doTestDownloaderCreateWithProxy (t , false , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
162
+ doTestDownloaderCreateWithProxy (t , false , nil , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
163
163
return nil
164
164
}, nil )
165
165
// Disable proxy
166
- doTestDownloaderCreateWithProxy (t , false , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
166
+ doTestDownloaderCreateWithProxy (t , false , nil , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
167
167
proxyCfg .Enable = false
168
168
return proxyCfg
169
169
}, nil )
170
170
// Enable system proxy but not set proxy environment variable
171
- doTestDownloaderCreateWithProxy (t , false , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
171
+ doTestDownloaderCreateWithProxy (t , false , nil , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
172
172
proxyCfg .System = true
173
173
return proxyCfg
174
174
}, nil )
175
175
// Enable proxy but error proxy environment variable
176
- doTestDownloaderCreateWithProxy (t , false , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
176
+ doTestDownloaderCreateWithProxy (t , false , nil , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
177
177
os .Setenv ("HTTP_PROXY" , "http://127.0.0.1:1234" )
178
178
os .Setenv ("HTTPS_PROXY" , "http://127.0.0.1:1234" )
179
179
proxyCfg .System = true
@@ -184,33 +184,50 @@ func TestDownloader_CreateWithProxy(t *testing.T) {
184
184
}
185
185
})
186
186
// Enable system proxy and set proxy environment variable
187
- doTestDownloaderCreateWithProxy (t , false , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
187
+ doTestDownloaderCreateWithProxy (t , false , nil , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
188
188
os .Setenv ("HTTP_PROXY" , proxyCfg .ToUrl ().String ())
189
189
os .Setenv ("HTTPS_PROXY" , proxyCfg .ToUrl ().String ())
190
190
proxyCfg .System = true
191
191
return proxyCfg
192
192
}, nil )
193
193
// Invalid proxy scheme
194
- doTestDownloaderCreateWithProxy (t , false , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
194
+ doTestDownloaderCreateWithProxy (t , false , nil , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
195
195
proxyCfg .Scheme = ""
196
196
return proxyCfg
197
197
}, nil )
198
198
// Invalid proxy host
199
- doTestDownloaderCreateWithProxy (t , false , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
199
+ doTestDownloaderCreateWithProxy (t , false , nil , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
200
200
proxyCfg .Host = ""
201
201
return proxyCfg
202
202
}, nil )
203
203
// Use proxy without auth
204
- doTestDownloaderCreateWithProxy (t , false , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
204
+ doTestDownloaderCreateWithProxy (t , false , nil , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
205
205
return proxyCfg
206
206
}, nil )
207
207
// Use proxy with auth
208
- doTestDownloaderCreateWithProxy (t , true , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
208
+ doTestDownloaderCreateWithProxy (t , true , nil , func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig {
209
209
return proxyCfg
210
210
}, nil )
211
+
212
+ // Request proxy mode follow
213
+ doTestDownloaderCreateWithProxy (t , false , func (reqProxy * base.RequestProxy ) * base.RequestProxy {
214
+ reqProxy .Mode = base .RequestProxyModeFollow
215
+ return reqProxy
216
+ }, nil , nil )
217
+
218
+ // Request proxy mode none
219
+ doTestDownloaderCreateWithProxy (t , false , func (reqProxy * base.RequestProxy ) * base.RequestProxy {
220
+ reqProxy .Mode = base .RequestProxyModeNone
221
+ return reqProxy
222
+ }, nil , nil )
223
+
224
+ // Request proxy mode custom
225
+ doTestDownloaderCreateWithProxy (t , false , func (reqProxy * base.RequestProxy ) * base.RequestProxy {
226
+ return reqProxy
227
+ }, nil , nil )
211
228
}
212
229
213
- func doTestDownloaderCreateWithProxy (t * testing.T , auth bool , buildProxyConfig func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig , errHandler func (err error )) {
230
+ func doTestDownloaderCreateWithProxy (t * testing.T , auth bool , buildReqProxy func ( reqProxy * base. RequestProxy ) * base. RequestProxy , buildProxyConfig func (proxyCfg * base.DownloaderProxyConfig ) * base.DownloaderProxyConfig , errHandler func (err error )) {
214
231
usr , pwd := "" , ""
215
232
if auth {
216
233
usr , pwd = "admin" , "123"
@@ -223,17 +240,29 @@ func doTestDownloaderCreateWithProxy(t *testing.T, auth bool, buildProxyConfig f
223
240
t .Fatal (err )
224
241
}
225
242
defer downloader .Clear ()
226
- downloader . cfg . DownloaderStoreConfig . Proxy = buildProxyConfig ( & base.DownloaderProxyConfig {
243
+ globalProxyCfg := & base.DownloaderProxyConfig {
227
244
Enable : true ,
228
245
Scheme : "socks5" ,
229
246
Host : proxyListener .Addr ().String (),
230
247
Usr : usr ,
231
248
Pwd : pwd ,
232
- })
249
+ }
250
+ if buildProxyConfig != nil {
251
+ globalProxyCfg = buildProxyConfig (globalProxyCfg )
252
+ }
253
+ downloader .cfg .DownloaderStoreConfig .Proxy = globalProxyCfg
233
254
234
255
req := & base.Request {
235
256
URL : test .ExternalDownloadUrl ,
236
257
}
258
+ if buildReqProxy != nil {
259
+ req .Proxy = buildReqProxy (& base.RequestProxy {
260
+ Scheme : "socks5" ,
261
+ Host : proxyListener .Addr ().String (),
262
+ Usr : usr ,
263
+ Pwd : pwd ,
264
+ })
265
+ }
237
266
rr , err := downloader .Resolve (req )
238
267
if err != nil {
239
268
if errHandler == nil {
0 commit comments