refs #12850 Merge branch '12850-docker-tag-version'
[arvados.git] / services / keep-web / handler.go
index c9148a562eb3bc86e53ec27944cffa2a8a6010ff..19a2040b4a5735551c0f7bf8a610c1fb109399b9 100644 (file)
@@ -91,8 +91,10 @@ func (h *handler) setup() {
 func (h *handler) serveStatus(w http.ResponseWriter, r *http.Request) {
        status := struct {
                cacheStats
+               Version string
        }{
                cacheStats: h.Config.Cache.Stats(),
+               Version:    version,
        }
        json.NewEncoder(w).Encode(status)
 }
@@ -139,6 +141,7 @@ func (uos *updateOnSuccess) WriteHeader(code int) {
 
 var (
        writeMethod = map[string]bool{
+               "COPY":   true,
                "DELETE": true,
                "MKCOL":  true,
                "MOVE":   true,
@@ -146,6 +149,7 @@ var (
                "RMCOL":  true,
        }
        webdavMethod = map[string]bool{
+               "COPY":     true,
                "DELETE":   true,
                "MKCOL":    true,
                "MOVE":     true,
@@ -200,7 +204,7 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
                        return
                }
                w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type, Range")
-               w.Header().Set("Access-Control-Allow-Methods", "DELETE, GET, MKCOL, MOVE, OPTIONS, POST, PROPFIND, PUT, RMCOL")
+               w.Header().Set("Access-Control-Allow-Methods", "COPY, DELETE, GET, MKCOL, MOVE, OPTIONS, POST, PROPFIND, PUT, RMCOL")
                w.Header().Set("Access-Control-Allow-Origin", "*")
                w.Header().Set("Access-Control-Max-Age", "86400")
                statusCode = http.StatusOK
@@ -415,9 +419,15 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
                statusCode, statusText = http.StatusInternalServerError, err.Error()
                return
        }
+
+       targetIsPDH := arvadosclient.PDHMatch(targetID)
+       if targetIsPDH && writeMethod[r.Method] {
+               statusCode, statusText = http.StatusMethodNotAllowed, errReadOnly.Error()
+               return
+       }
+
        if webdavMethod[r.Method] {
-               writing := !arvadosclient.PDHMatch(targetID) && writeMethod[r.Method]
-               if writing {
+               if writeMethod[r.Method] {
                        // Save the collection only if/when all
                        // webdav->filesystem operations succeed --
                        // and send a 500 error if the modified
@@ -431,8 +441,9 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
                h := webdav.Handler{
                        Prefix: "/" + strings.Join(pathParts[:stripParts], "/"),
                        FileSystem: &webdavFS{
-                               collfs:  fs,
-                               writing: writing,
+                               collfs:        fs,
+                               writing:       writeMethod[r.Method],
+                               alwaysReadEOF: r.Method == "PROPFIND",
                        },
                        LockSystem: h.webdavLS,
                        Logger: func(_ *http.Request, err error) {