mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-25 09:40:13 +08:00
Revert "fileserver: Redirect within the original URL (#4179)"
This reverts commit f9b54454a1
.
/cc @diamondburned (see #4205)
This commit is contained in:
parent
89aa3a5ef3
commit
8848df9c5d
|
@ -47,11 +47,10 @@ func (fsrv *FileServer) serveBrowse(root, dirPath string, w http.ResponseWriter,
|
|||
// 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
|
||||
oldReq := r.Context().Value(caddyhttp.OriginalRequestCtxKey).(http.Request)
|
||||
if !strings.HasSuffix(oldReq.URL.Path, "/") {
|
||||
fsrv.logger.Debug("redirecting to trailing slash to preserve hrefs", zap.String("request_path", oldReq.URL.Path))
|
||||
oldReq.URL.Path += "/"
|
||||
http.Redirect(w, r, oldReq.URL.String(), http.StatusMovedPermanently)
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user