Skip to content

Commit 9798ea1

Browse files
committed
feat: add bearer token support
1 parent d375e85 commit 9798ea1

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pkg/net/http.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ func (h *HTTPDownloader) DownloadFile() error {
115115

116116
if h.UserName != "" && h.Password != "" {
117117
req.SetBasicAuth(h.UserName, h.Password)
118+
} else if h.Password != "" {
119+
req.Header.Set("Authorization", "Bearer "+h.Password)
118120
}
121+
119122
var tr http.RoundTripper
120123
if h.RoundTripper != nil {
121124
tr = h.RoundTripper

pkg/net/multi_thread.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ func (d *MultiThreadDownloader) WithBasicAuth(username, password string) *MultiT
7070
return d
7171
}
7272

73+
func (d *MultiThreadDownloader) WithBearerToken(bearerToken string) *MultiThreadDownloader {
74+
d.password = bearerToken
75+
return d
76+
}
77+
7378
// Download starts to download the target URL
7479
func (d *MultiThreadDownloader) Download(targetURL, targetFilePath string, thread int) (err error) {
7580
// get the total size of the target file

0 commit comments

Comments
 (0)