From 7d7434c9ce9778adf7b7ff6c3a6575ea1c11ed01 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 26 Nov 2020 09:37:42 -0700 Subject: fileserver: Add debug logging --- modules/caddyhttp/fileserver/browse.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'modules/caddyhttp/fileserver/browse.go') diff --git a/modules/caddyhttp/fileserver/browse.go b/modules/caddyhttp/fileserver/browse.go index af3620a..1f6986f 100644 --- a/modules/caddyhttp/fileserver/browse.go +++ b/modules/caddyhttp/fileserver/browse.go @@ -25,6 +25,7 @@ import ( "github.com/caddyserver/caddy/v2" "github.com/caddyserver/caddy/v2/modules/caddyhttp" + "go.uber.org/zap" ) // Browse configures directory browsing. @@ -36,11 +37,16 @@ type Browse struct { } func (fsrv *FileServer) serveBrowse(root, dirPath string, w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error { + fsrv.logger.Debug("browse enabled; listing directory contents", + zap.String("path", dirPath), + zap.String("root", root)) + // navigation on the client-side gets messed up if the // URL doesn't end in a trailing slash because hrefs like // "/b/c" on a path like "/a" end up going to "/b/c" instead // of "/a/b/c" - so we have to redirect in this case if !strings.HasSuffix(r.URL.Path, "/") { + fsrv.logger.Debug("redirecting to trailing slash to preserve hrefs", zap.String("request_path", r.URL.Path)) r.URL.Path += "/" http.Redirect(w, r, r.URL.String(), http.StatusMovedPermanently) return nil -- cgit v1.2.3