diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2022-01-01 22:34:13 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-01 22:34:13 -0800 |
| commit | 9b941773805400c520558d83aed633adc821988c (patch) | |
| tree | 55cac459c1219bf7b8a50049572260917634ccfc /weed/util/http_util.go | |
| parent | 34742be0295998c2105a5ee50e3e77ef2397c403 (diff) | |
| parent | 99abddf3769a5e4a25c72e67df9106e41b7aa8f3 (diff) | |
| download | seaweedfs-9b941773805400c520558d83aed633adc821988c.tar.xz seaweedfs-9b941773805400c520558d83aed633adc821988c.zip | |
Merge pull request #2543 from skurfuerst/seaweedfs-158
FEATURE: add JWT to HTTP endpoints of Filer and use them in S3 Client
Diffstat (limited to 'weed/util/http_util.go')
| -rw-r--r-- | weed/util/http_util.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/weed/util/http_util.go b/weed/util/http_util.go index 34765d68e..8b66c6dc1 100644 --- a/weed/util/http_util.go +++ b/weed/util/http_util.go @@ -180,7 +180,16 @@ func GetUrlStream(url string, values url.Values, readFn func(io.Reader) error) e } func DownloadFile(fileUrl string, jwt string) (filename string, header http.Header, resp *http.Response, e error) { - response, err := client.Get(fileUrl) + req, err := http.NewRequest("GET", fileUrl, nil) + if err != nil { + return "", nil, nil, err + } + + if len(jwt) > 0 { + req.Header.Set("Authorization", "BEARER "+jwt) + } + + response, err := client.Do(req) if err != nil { return "", nil, nil, err } @@ -358,7 +367,7 @@ func readEncryptedUrl(fileUrl string, cipherKey []byte, isContentCompressed bool return false, nil } -func ReadUrlAsReaderCloser(fileUrl string, rangeHeader string) (io.ReadCloser, error) { +func ReadUrlAsReaderCloser(fileUrl string, jwt string, rangeHeader string) (io.ReadCloser, error) { req, err := http.NewRequest("GET", fileUrl, nil) if err != nil { @@ -370,6 +379,10 @@ func ReadUrlAsReaderCloser(fileUrl string, rangeHeader string) (io.ReadCloser, e req.Header.Add("Accept-Encoding", "gzip") } + if len(jwt) > 0 { + req.Header.Set("Authorization", "BEARER "+jwt) + } + r, err := client.Do(req) if err != nil { return nil, err |
