mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-20 22:52:58 -05:00
fileserver: Canonical redir when whole path is stripped (#4549)
This commit is contained in:
parent
bc447e307f
commit
15c95e9d5b
1 changed files with 4 additions and 1 deletions
|
@ -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,
|
// original URI is necessary because that's the URI the browser knows,
|
||||||
// we don't want to redirect from internally-rewritten URIs.)
|
// we don't want to redirect from internally-rewritten URIs.)
|
||||||
// See https://github.com/caddyserver/caddy/issues/4205.
|
// 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)
|
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, "/") {
|
if !strings.HasSuffix(origReq.URL.Path, "/") {
|
||||||
fsrv.logger.Debug("redirecting to trailing slash to preserve hrefs", zap.String("request_path", r.URL.Path))
|
fsrv.logger.Debug("redirecting to trailing slash to preserve hrefs", zap.String("request_path", r.URL.Path))
|
||||||
origReq.URL.Path += "/"
|
origReq.URL.Path += "/"
|
||||||
|
|
Loading…
Add table
Reference in a new issue