diff --git a/unmaintained/repeated_vacuum/repeated_vacuum.go b/unmaintained/repeated_vacuum/repeated_vacuum.go index 893f4a68a2c..eb2de27055d 100644 --- a/unmaintained/repeated_vacuum/repeated_vacuum.go +++ b/unmaintained/repeated_vacuum/repeated_vacuum.go @@ -1,6 +1,7 @@ package main import ( + "context" "flag" "fmt" "github.com/seaweedfs/seaweedfs/weed/pb" @@ -47,7 +48,7 @@ func main() { assignResult, targetUrl := genFile(grpcDialOption, i) - util.Delete(targetUrl, string(assignResult.Auth)) + util.Delete(targetUrl, string(assignResult.Auth), "") } diff --git a/weed/command/benchmark.go b/weed/command/benchmark.go index 2aa9d1e98d8..214c74293ee 100644 --- a/weed/command/benchmark.go +++ b/weed/command/benchmark.go @@ -219,7 +219,13 @@ func writeFiles(idChan chan int, fileIdLineChan chan string, s *stat) { if isSecure { jwtAuthorization = operation.LookupJwt(b.masterClient.GetMaster(context.Background()), b.grpcDialOption, df.fp.Fid) } - if e := util.Delete(fmt.Sprintf("http://%s/%s", df.fp.Server, df.fp.Fid), string(jwtAuthorization)); e == nil { + var authHeader string + if *b.username != "" { + auth := *b.username + ":" + *b.password + authHeader = "Basic " + base64.StdEncoding.EncodeToString([]byte(auth)) + } + + if e := util.Delete(fmt.Sprintf("http://%s/%s", df.fp.Server, df.fp.Fid), string(jwtAuthorization), authHeader); e == nil { s.completed++ } else { s.failed++ diff --git a/weed/shell/command_s3_clean_uploads.go b/weed/shell/command_s3_clean_uploads.go index 2be61f72ad9..a352a7bef43 100644 --- a/weed/shell/command_s3_clean_uploads.go +++ b/weed/shell/command_s3_clean_uploads.go @@ -90,7 +90,7 @@ func (c *commandS3CleanUploads) cleanupUploads(commandEnv *CommandEnv, writer io deleteUrl := fmt.Sprintf("http://%s%s/%s?recursive=true&ignoreRecursiveError=true", commandEnv.option.FilerAddress.ToHttpAddress(), uploadsDir, staleUpload) fmt.Fprintf(writer, "purge %s\n", deleteUrl) - err = util.Delete(deleteUrl, string(encodedJwt)) + err = util.Delete(deleteUrl, string(encodedJwt), "") if err != nil && err.Error() != "" { return fmt.Errorf("purge %s/%s: %v", uploadsDir, staleUpload, err) } diff --git a/weed/topology/store_replicate.go b/weed/topology/store_replicate.go index e1b83a2843f..c4dedb9b111 100644 --- a/weed/topology/store_replicate.go +++ b/weed/topology/store_replicate.go @@ -141,7 +141,7 @@ func ReplicatedDelete(masterFn operation.GetMasterFn, grpcDialOption grpc.DialOp if len(remoteLocations) > 0 { //send to other replica locations if err = DistributedOperation(remoteLocations, func(location operation.Location) error { - return util.Delete("http://"+location.Url+r.URL.Path+"?type=replicate", string(jwt)) + return util.Delete("http://"+location.Url+r.URL.Path+"?type=replicate", string(jwt), r.Header.Get("Authorization")) }); err != nil { size = 0 } diff --git a/weed/util/http_util.go b/weed/util/http_util.go index 837b3ccb6e1..73e6fc377e7 100644 --- a/weed/util/http_util.go +++ b/weed/util/http_util.go @@ -61,7 +61,7 @@ func GetAuthenticated(url, jwt string) ([]byte, bool, error) { if err != nil { return nil, true, err } - maybeAddAuth(request, jwt) + maybeAddAuth(request, jwt, "") request.Header.Add("Accept-Encoding", "gzip") response, err := client.Do(request) @@ -105,15 +105,17 @@ func Head(url string) (http.Header, error) { return r.Header, nil } -func maybeAddAuth(req *http.Request, jwt string) { +func maybeAddAuth(req *http.Request, jwt, authHeader string) { if jwt != "" { req.Header.Set("Authorization", "BEARER "+string(jwt)) + } else if authHeader != "" { + req.Header.Set("Authorization", authHeader) } } -func Delete(url string, jwt string) error { +func Delete(url string, jwt, authHeader string) error { req, err := http.NewRequest(http.MethodDelete, url, nil) - maybeAddAuth(req, jwt) + maybeAddAuth(req, jwt, authHeader) if err != nil { return err } @@ -141,7 +143,7 @@ func Delete(url string, jwt string) error { func DeleteProxied(url string, jwt string) (body []byte, httpStatus int, err error) { req, err := http.NewRequest(http.MethodDelete, url, nil) - maybeAddAuth(req, jwt) + maybeAddAuth(req, jwt, "") if err != nil { return } @@ -199,7 +201,7 @@ func DownloadFile(fileUrl string, jwt string) (filename string, header http.Head return "", nil, nil, err } - maybeAddAuth(req, jwt) + maybeAddAuth(req, jwt, "") response, err := client.Do(req) if err != nil { @@ -311,7 +313,7 @@ func ReadUrlAsStreamAuthenticated(fileUrl, jwt string, cipherKey []byte, isConte } req, err := http.NewRequest(http.MethodGet, fileUrl, nil) - maybeAddAuth(req, jwt) + maybeAddAuth(req, jwt, "") if err != nil { return false, err } @@ -401,7 +403,7 @@ func ReadUrlAsReaderCloser(fileUrl string, jwt string, rangeHeader string) (*htt req.Header.Add("Accept-Encoding", "gzip") } - maybeAddAuth(req, jwt) + maybeAddAuth(req, jwt, "") r, err := client.Do(req) if err != nil {