16535: Add HeadBucket API.
authorTom Clegg <tom@tomclegg.ca>
Thu, 30 Jul 2020 20:38:26 +0000 (16:38 -0400)
committerTom Clegg <tom@tomclegg.ca>
Thu, 30 Jul 2020 20:38:26 +0000 (16:38 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

services/keep-web/s3.go

index 7a25e9277e755ae10d295663c03a31018d554f34..05764beee0ab5612b67a7831833384cb4b3f8f73 100644 (file)
@@ -65,8 +65,10 @@ func (h *handler) serveS3(w http.ResponseWriter, r *http.Request) bool {
        fs := client.SiteFileSystem(kc)
        fs.ForwardSlashNameSubstitution(h.Config.cluster.Collections.ForwardSlashNameSubstitution)
 
+       objectNameGiven := strings.Count(strings.TrimSuffix(r.URL.Path, "/"), "/") > 1
+
        switch {
-       case r.Method == "GET" && strings.Count(strings.TrimSuffix(r.URL.Path, "/"), "/") == 1:
+       case r.Method == "GET" && !objectNameGiven:
                // Path is "/{uuid}" or "/{uuid}/", has no object name
                if _, ok := r.URL.Query()["versioning"]; ok {
                        // GetBucketVersioning
@@ -78,9 +80,20 @@ func (h *handler) serveS3(w http.ResponseWriter, r *http.Request) bool {
                        h.s3list(w, r, fs)
                }
                return true
-       case r.Method == "GET":
+       case r.Method == "GET" || r.Method == "HEAD":
                fspath := "/by_id" + r.URL.Path
                fi, err := fs.Stat(fspath)
+               if r.Method == "HEAD" && !objectNameGiven {
+                       // HeadBucket
+                       if err != nil && fi.IsDir() {
+                               w.WriteHeader(http.StatusOK)
+                       } else if os.IsNotExist(err) {
+                               w.WriteHeader(http.StatusNotFound)
+                       } else {
+                               http.Error(w, err.Error(), http.StatusBadGateway)
+                       }
+                       return true
+               }
                if os.IsNotExist(err) ||
                        (err != nil && err.Error() == "not a directory") ||
                        (fi != nil && fi.IsDir()) {