@marcel91200 / caddy Mirror · read-only / commits / 15c95e9d
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 21:45 UTC

fileserver: Canonical redir when whole path is stripped (#4549)

Francis Lavoie committed Mar 1, 2022 at 17:32 UTC 15c95e9d5b330a9590bbd7271264d9d47dd6e643
1 file changed +4 -1
modules/caddyhttp/fileserver/browse.go
+4 -1
@@ -60,8 +60,11 @@ func (fsrv *FileServer) serveBrowse(root, dirPath string, w http.ResponseWriter,
60 // original URI is necessary because that's the URI the browser knows,
61 // we don't want to redirect from internally-rewritten URIs.)
62 // See https://github.com/caddyserver/caddy/issues/4205.
63 + // We also redirect if the path is empty, because this implies the path
64 + // prefix was fully stripped away by a `handle_path` handler for example.
65 + // See https://github.com/caddyserver/caddy/issues/4466.
66 origReq := r.Context().Value(caddyhttp.OriginalRequestCtxKey).(http.Request)
64 - if path.Base(origReq.URL.Path) == path.Base(r.URL.Path) {
67 + if r.URL.Path == "" || path.Base(origReq.URL.Path) == path.Base(r.URL.Path) {
68 if !strings.HasSuffix(origReq.URL.Path, "/") {
69 fsrv.logger.Debug("redirecting to trailing slash to preserve hrefs", zap.String("request_path", r.URL.Path))
70 origReq.URL.Path += "/"