X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=handler.go;h=a8a9e31b03835e3fae3078e84f3399b328717b38;hb=0fe97b4cad480d0584e3d52f579662a7910d9984;hp=1fcbb7e821a33b5f3156feb8a8fbe011f2c29a9d;hpb=0b1221d2cfb6c7a77aa428e77fd586229dbc5fb7;p=godlighty.git diff --git a/handler.go b/handler.go index 1fcbb7e..a8a9e31 100644 --- a/handler.go +++ b/handler.go @@ -86,6 +86,7 @@ func (h Handler) Handle( ) http.NotFound(w, r) } + w.Header().Set("Server", Version) if cfg == nil { notFound() return @@ -140,7 +141,15 @@ func (h Handler) Handle( return } - if cfg.WebDAV && (r.Method == http.MethodHead || + pthOrig := path.Clean(path.Join(cfg.Root, r.URL.Path)) + pth := pthOrig + fi, err := os.Stat(pth) + if err != nil { + notFound() + return + } + + if cfg.WebDAV && (((r.Method == http.MethodHead) && fi.IsDir()) || r.Method == http.MethodOptions || r.Method == "PROPFIND") { dav := webdav.Handler{ @@ -166,17 +175,11 @@ func (h Handler) Handle( http.Error(w, "method not allowed", http.StatusMethodNotAllowed) return } + var fd *os.File var contentType string var etag string - pthOrig := path.Clean(path.Join(cfg.Root, r.URL.Path)) - pth := pthOrig -IndexLookup: - fi, err := os.Stat(pth) - if err != nil { - notFound() - return - } +IndexLookuped: if fi.IsDir() { if cfg.DirList { entries, err := os.ReadDir(pth) @@ -217,7 +220,12 @@ IndexLookup: p := path.Join(pth, index) if _, err := os.Stat(p); err == nil { pth = p - goto IndexLookup + fi, err = os.Stat(pth) + if err != nil { + notFound() + return + } + goto IndexLookuped } } notFound() @@ -277,7 +285,6 @@ SkipMeta4: contentTypeBase := strings.SplitN(contentType, ";", 2)[0] w.Header().Set("Content-Type", contentType) - w.Header().Set("Server", Version) if etag != "" { w.Header().Set("ETag", etag) }