From 67288efc74e70a1ac7f511a5eddfb582319fa67b Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Thu, 30 Jul 2020 16:38:26 -0400 Subject: [PATCH] 16535: Add HeadBucket API. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- services/keep-web/s3.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/services/keep-web/s3.go b/services/keep-web/s3.go index 7a25e9277e..05764beee0 100644 --- a/services/keep-web/s3.go +++ b/services/keep-web/s3.go @@ -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()) { -- 2.30.2