diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2021-06-14 09:03:56 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2021-06-14 09:04:30 -0600 |
commit | 8848df9c5d372a559d01512b7a4ef00e38867b55 (patch) | |
tree | 6c3d33b403b7f015204fea708582d331d7e51d01 /modules/caddyhttp/fileserver/staticfiles.go | |
parent | 89aa3a5ef3e0da58d8a165ffe4c073fda52994db (diff) |
Revert "fileserver: Redirect within the original URL (#4179)"
This reverts commit f9b54454a19e2b070159ce8d2af76d819658244e.
/cc @diamondburned (see #4205)
Diffstat (limited to 'modules/caddyhttp/fileserver/staticfiles.go')
-rw-r--r-- | modules/caddyhttp/fileserver/staticfiles.go | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go index 87e0a77..f2320aa 100644 --- a/modules/caddyhttp/fileserver/staticfiles.go +++ b/modules/caddyhttp/fileserver/staticfiles.go @@ -243,14 +243,12 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c // trailing slash - not enforcing this can break relative hrefs // in HTML (see https://github.com/caddyserver/caddy/issues/2741) if fsrv.CanonicalURIs == nil || *fsrv.CanonicalURIs { - oldReq := r.Context().Value(caddyhttp.OriginalRequestCtxKey).(http.Request) - - if implicitIndexFile && !strings.HasSuffix(oldReq.URL.Path, "/") { - fsrv.logger.Debug("redirecting to canonical URI (adding trailing slash for directory)", zap.String("path", oldReq.URL.Path)) - return redirect(w, r, oldReq.URL.Path+"/") - } else if !implicitIndexFile && strings.HasSuffix(oldReq.URL.Path, "/") { - fsrv.logger.Debug("redirecting to canonical URI (removing trailing slash for file)", zap.String("path", oldReq.URL.Path)) - return redirect(w, r, oldReq.URL.Path[:len(oldReq.URL.Path)-1]) + if implicitIndexFile && !strings.HasSuffix(r.URL.Path, "/") { + fsrv.logger.Debug("redirecting to canonical URI (adding trailing slash for directory)", zap.String("path", r.URL.Path)) + return redirect(w, r, r.URL.Path+"/") + } else if !implicitIndexFile && strings.HasSuffix(r.URL.Path, "/") { + fsrv.logger.Debug("redirecting to canonical URI (removing trailing slash for file)", zap.String("path", r.URL.Path)) + return redirect(w, r, r.URL.Path[:len(r.URL.Path)-1]) } } |