(r *http.Request, authPairs map[string]string)
| 75 | } |
| 76 | |
| 77 | func directUploadURL(r *http.Request, authPairs map[string]string) (string, bool) { |
| 78 | if r.Method != http.MethodPut || r.ContentLength < 0 { |
| 79 | return "", false |
| 80 | } |
| 81 | if hasNonObjectQuery(r) || !s3RequestAuthorized(r, authPairs) { |
| 82 | return "", false |
| 83 | } |
| 84 | if r.Header.Get("X-Amz-Copy-Source") != "" || |
| 85 | r.Header.Get("X-Amz-Content-Sha256") == "STREAMING-AWS4-HMAC-SHA256-PAYLOAD" { |
| 86 | return "", false |
| 87 | } |
| 88 | bucketName, objectName, ok := parseObjectPath(r.URL.Path) |
| 89 | if !ok || strings.HasSuffix(objectName, "/") { |
| 90 | return "", false |
| 91 | } |
| 92 | bucket, err := getBucketByName(bucketName) |
| 93 | if err != nil { |
| 94 | return "", false |
| 95 | } |
| 96 | reqPath := path.Join(bucket.Path, objectName) |
| 97 | storage, dstDirActualPath, err := op.GetStorageAndActualPath(path.Dir(reqPath)) |
| 98 | if err != nil || storage.Config().NoUpload { |
| 99 | return "", false |
| 100 | } |
| 101 | info, err := op.GetDirectUploadInfo(r.Context(), "HttpDirect", storage, dstDirActualPath, path.Base(reqPath), r.ContentLength, true) |
| 102 | if err != nil { |
| 103 | return "", false |
| 104 | } |
| 105 | httpInfo, ok := asHTTPDirectUploadInfo(info) |
| 106 | if !ok { |
| 107 | return "", false |
| 108 | } |
| 109 | method := httpInfo.Method |
| 110 | if method == "" { |
| 111 | method = http.MethodPut |
| 112 | } |
| 113 | if !strings.EqualFold(method, http.MethodPut) || httpInfo.UploadURL == "" || |
| 114 | httpInfo.ChunkSize > 0 || len(httpInfo.Headers) > 0 { |
| 115 | return "", false |
| 116 | } |
| 117 | return httpInfo.UploadURL, true |
| 118 | } |
| 119 | |
| 120 | func asHTTPDirectUploadInfo(info any) (*model.HttpDirectUploadInfo, bool) { |
| 121 | switch v := info.(type) { |
no test coverage detected