@@ -219,6 +219,7 @@ func DownloadFileWithMultipleThreadKeepParts(targetURL, targetFilePath string, t
219
219
type ContinueDownloader struct {
220
220
downloader * HTTPDownloader
221
221
222
+ UserName , Password string
222
223
Timeout time.Duration
223
224
Context context.Context
224
225
roundTripper http.RoundTripper
@@ -261,6 +262,13 @@ func (c *ContinueDownloader) WithTimeout(timeout time.Duration) *ContinueDownloa
261
262
return c
262
263
}
263
264
265
+ // WithBasicAuth sets the basic auth
266
+ func (c * ContinueDownloader ) WithBasicAuth (username , password string ) * ContinueDownloader {
267
+ c .UserName = username
268
+ c .Password = password
269
+ return c
270
+ }
271
+
264
272
// DownloadWithContinue downloads the files continuously
265
273
func (c * ContinueDownloader ) DownloadWithContinue (targetURL , output string , index , continueAt , end int64 , showProgress bool ) (err error ) {
266
274
c .downloader = & HTTPDownloader {
@@ -270,6 +278,8 @@ func (c *ContinueDownloader) DownloadWithContinue(targetURL, output string, inde
270
278
NoProxy : c .noProxy ,
271
279
RoundTripper : c .roundTripper ,
272
280
InsecureSkipVerify : c .insecureSkipVerify ,
281
+ UserName : c .UserName ,
282
+ Password : c .Password ,
273
283
Context : c .Context ,
274
284
Timeout : c .Timeout ,
275
285
}
@@ -293,16 +303,18 @@ func (c *ContinueDownloader) DownloadWithContinue(targetURL, output string, inde
293
303
return
294
304
}
295
305
296
- // DetectSizeWithRoundTripper returns the size of target resource
297
- func DetectSizeWithRoundTripper (targetURL , output string , showProgress , noProxy , insecureSkipVerify bool ,
298
- roundTripper http.RoundTripper , timeout time.Duration ) (total int64 , rangeSupport bool , err error ) {
306
+ // DetectSizeWithRoundTripperAndAuth returns the size of target resource
307
+ func DetectSizeWithRoundTripperAndAuth (targetURL , output string , showProgress , noProxy , insecureSkipVerify bool ,
308
+ roundTripper http.RoundTripper , username , password string , timeout time.Duration ) (total int64 , rangeSupport bool , err error ) {
299
309
downloader := HTTPDownloader {
300
310
TargetFilePath : output ,
301
311
URL : targetURL ,
302
312
ShowProgress : showProgress ,
303
313
RoundTripper : roundTripper ,
304
314
NoProxy : false , // below HTTP request does not need proxy
305
315
InsecureSkipVerify : insecureSkipVerify ,
316
+ UserName : username ,
317
+ Password : password ,
306
318
Timeout : timeout ,
307
319
}
308
320
@@ -331,6 +343,13 @@ func DetectSizeWithRoundTripper(targetURL, output string, showProgress, noProxy,
331
343
return
332
344
}
333
345
346
+ // DetectSizeWithRoundTripper returns the size of target resource
347
+ // Deprecated, use DetectSizeWithRoundTripperAndAuth instead
348
+ func DetectSizeWithRoundTripper (targetURL , output string , showProgress , noProxy , insecureSkipVerify bool ,
349
+ roundTripper http.RoundTripper , timeout time.Duration ) (total int64 , rangeSupport bool , err error ) {
350
+ return DetectSizeWithRoundTripperAndAuth (targetURL , output , showProgress , noProxy , insecureSkipVerify , roundTripper , "" , "" , timeout )
351
+ }
352
+
334
353
// ParseSuggestedFilename parse the filename from resp header,More details from https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
335
354
func ParseSuggestedFilename (header http.Header , filepath string ) (filename string ) {
336
355
if disposition , ok := header ["Content-Disposition" ]; ok && len (disposition ) >= 1 {
0 commit comments