diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-11-26 09:37:42 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-11-26 09:37:42 -0700 |
commit | 7d7434c9ce9778adf7b7ff6c3a6575ea1c11ed01 (patch) | |
tree | 357751e55af98608901c5614d1c2dc775d74d76e /modules/caddyhttp/fileserver/browse.go | |
parent | 53aa60afff2e66b4a2b2ca6968fe5cb6c8567437 (diff) |
fileserver: Add debug logging
Diffstat (limited to 'modules/caddyhttp/fileserver/browse.go')
-rw-r--r-- | modules/caddyhttp/fileserver/browse.go | 6 |
1 files changed, 6 insertions, 0 deletions
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 |