summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/fileserver/browse.go
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2022-03-01 17:32:39 -0500
committerGitHub <noreply@github.com>2022-03-01 15:32:39 -0700
commit15c95e9d5b330a9590bbd7271264d9d47dd6e643 (patch)
tree0a76d841863100e024b784593b771574bdaac261 /modules/caddyhttp/fileserver/browse.go
parentbc447e307f195b80eeec0f6157e0d8e641af9155 (diff)
fileserver: Canonical redir when whole path is stripped (#4549)
Diffstat (limited to 'modules/caddyhttp/fileserver/browse.go')
-rw-r--r--modules/caddyhttp/fileserver/browse.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/modules/caddyhttp/fileserver/browse.go b/modules/caddyhttp/fileserver/browse.go
index d076aec..f308281 100644
--- a/modules/caddyhttp/fileserver/browse.go
+++ b/modules/caddyhttp/fileserver/browse.go
@@ -60,8 +60,11 @@ func (fsrv *FileServer) serveBrowse(root, dirPath string, w http.ResponseWriter,
// original URI is necessary because that's the URI the browser knows,
// we don't want to redirect from internally-rewritten URIs.)
// See https://github.com/caddyserver/caddy/issues/4205.
+ // We also redirect if the path is empty, because this implies the path
+ // prefix was fully stripped away by a `handle_path` handler for example.
+ // See https://github.com/caddyserver/caddy/issues/4466.
origReq := r.Context().Value(caddyhttp.OriginalRequestCtxKey).(http.Request)
- if path.Base(origReq.URL.Path) == path.Base(r.URL.Path) {
+ if r.URL.Path == "" || path.Base(origReq.URL.Path) == path.Base(r.URL.Path) {
if !strings.HasSuffix(origReq.URL.Path, "/") {
fsrv.logger.Debug("redirecting to trailing slash to preserve hrefs", zap.String("request_path", r.URL.Path))
origReq.URL.Path += "/"