@@ -219,6 +219,7 @@ func DownloadFileWithMultipleThreadKeepParts(targetURL, targetFilePath string, t
219219type ContinueDownloader struct {
220220 downloader * HTTPDownloader
221221
222+ UserName , Password string
222223 Timeout time.Duration
223224 Context context.Context
224225 roundTripper http.RoundTripper
@@ -261,6 +262,13 @@ func (c *ContinueDownloader) WithTimeout(timeout time.Duration) *ContinueDownloa
261262 return c
262263}
263264
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+
264272// DownloadWithContinue downloads the files continuously
265273func (c * ContinueDownloader ) DownloadWithContinue (targetURL , output string , index , continueAt , end int64 , showProgress bool ) (err error ) {
266274 c .downloader = & HTTPDownloader {
@@ -270,6 +278,8 @@ func (c *ContinueDownloader) DownloadWithContinue(targetURL, output string, inde
270278 NoProxy : c .noProxy ,
271279 RoundTripper : c .roundTripper ,
272280 InsecureSkipVerify : c .insecureSkipVerify ,
281+ UserName : c .UserName ,
282+ Password : c .Password ,
273283 Context : c .Context ,
274284 Timeout : c .Timeout ,
275285 }
@@ -293,16 +303,18 @@ func (c *ContinueDownloader) DownloadWithContinue(targetURL, output string, inde
293303 return
294304}
295305
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 ) {
299309 downloader := HTTPDownloader {
300310 TargetFilePath : output ,
301311 URL : targetURL ,
302312 ShowProgress : showProgress ,
303313 RoundTripper : roundTripper ,
304314 NoProxy : false , // below HTTP request does not need proxy
305315 InsecureSkipVerify : insecureSkipVerify ,
316+ UserName : username ,
317+ Password : password ,
306318 Timeout : timeout ,
307319 }
308320
@@ -331,6 +343,13 @@ func DetectSizeWithRoundTripper(targetURL, output string, showProgress, noProxy,
331343 return
332344}
333345
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+
334353// ParseSuggestedFilename parse the filename from resp header,More details from https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
335354func ParseSuggestedFilename (header http.Header , filepath string ) (filename string ) {
336355 if disposition , ok := header ["Content-Disposition" ]; ok && len (disposition ) >= 1 {
0 commit comments