From 4a0c6ccd0b189f13311013706223075dc611a105 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 16 Apr 2017 14:01:11 +0100 Subject: [PATCH] close #85\ GET, for collections, will return the same as PROPFIND Former-commit-id: 41c186e17e16de45496d801ae93ec1ebb354278a [formerly ed98a85eedbb5ade8a15baafc6431eec423096a3] [formerly dd7355277eb837d12ae626b80b6b692426f824ca [formerly a72ea31b1752bfe25407e4a2ac8f30b4b8ae4179]] Former-commit-id: 3d98abf4da701a5919a63d38c2331e96089baae7 [formerly 8dbca8f8ed8f3a87d244fb8aa0cc8bf523e51a67] Former-commit-id: 07c11f93beb2fc10fb0253424c1d55a4178d7010 --- filemanager.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/filemanager.go b/filemanager.go index 01949d99..993d7e88 100644 --- a/filemanager.go +++ b/filemanager.go @@ -6,6 +6,8 @@ package filemanager import ( e "errors" "net/http" + "os" + "path/filepath" "strings" "github.com/hacdias/caddy-filemanager/assets" @@ -67,6 +69,29 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err } switch r.Method { + case "GET": + // Excerpt from RFC4918, section 9.4: + // + // GET, when applied to a collection, may return the contents of an + // "index.html" resource, a human-readable view of the contents of + // the collection, or something else altogether. + // + // It was decided on https://github.com/hacdias/caddy-filemanager/issues/85 + // that GET, for collection, will return the same as PROPFIND method. + path := strings.Replace(r.URL.Path, c.WebDavURL, "", 1) + path = user.Scope + "/" + path + path = filepath.Clean(path) + + var i os.FileInfo + i, err = os.Stat(path) + if err != nil { + // Is there any error? WebDav will handle it... no worries. + break + } + + if i.IsDir() { + r.Method = "PROPFIND" + } case "PROPPATCH", "MOVE", "PATCH", "PUT", "DELETE": if !user.AllowEdit { return http.StatusForbidden, nil