mirror of
https://github.com/caddyserver/caddy.git
synced 2026-11-20 23:09:46 +00:00
Merge d8c45ca9c6 into 7ce9f08237
This commit is contained in:
commit
7de8f61b2e
2 changed files with 7 additions and 7 deletions
|
|
@ -128,7 +128,7 @@ func (fsrv *FileServer) serveBrowse(fileSystem fs.FS, root, dirPath string, w ht
|
|||
case errors.Is(err, fs.ErrPermission):
|
||||
return caddyhttp.Error(http.StatusForbidden, err)
|
||||
case errors.Is(err, fs.ErrNotExist):
|
||||
return fsrv.notFound(w, r, next)
|
||||
return fsrv.notFound(w, r, next, err)
|
||||
case err != nil:
|
||||
return caddyhttp.Error(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
|||
if err != nil {
|
||||
err = fsrv.mapDirOpenError(fileSystem, err, filename)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return fsrv.notFound(w, r, next)
|
||||
return fsrv.notFound(w, r, next, err)
|
||||
} else if errors.Is(err, fs.ErrInvalid) {
|
||||
return caddyhttp.Error(http.StatusBadRequest, err)
|
||||
} else if errors.Is(err, fs.ErrPermission) {
|
||||
|
|
@ -395,7 +395,7 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
|||
if fsrv.Browse != nil && !fileHidden(filename, filesToHide) {
|
||||
return fsrv.serveBrowse(fileSystem, root, filename, w, r, next)
|
||||
}
|
||||
return fsrv.notFound(w, r, next)
|
||||
return fsrv.notFound(w, r, next, fmt.Errorf("directory without index file or browse enabled"))
|
||||
}
|
||||
|
||||
// one last check to ensure the file isn't hidden (we might
|
||||
|
|
@ -407,7 +407,7 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
|||
zap.Strings("files_to_hide", filesToHide),
|
||||
)
|
||||
}
|
||||
return fsrv.notFound(w, r, next)
|
||||
return fsrv.notFound(w, r, next, fmt.Errorf("file is hidden"))
|
||||
}
|
||||
|
||||
// if URL canonicalization is enabled, we need to enforce trailing
|
||||
|
|
@ -540,7 +540,7 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
|||
if err != nil {
|
||||
if herr, ok := err.(caddyhttp.HandlerError); ok &&
|
||||
herr.StatusCode == http.StatusNotFound {
|
||||
return fsrv.notFound(w, r, next)
|
||||
return fsrv.notFound(w, r, next, herr.Err)
|
||||
}
|
||||
return err // error is already structured
|
||||
}
|
||||
|
|
@ -811,11 +811,11 @@ func foldCase(s string) string {
|
|||
|
||||
// notFound returns a 404 error or, if pass-thru is enabled,
|
||||
// it calls the next handler in the chain.
|
||||
func (fsrv *FileServer) notFound(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
|
||||
func (fsrv *FileServer) notFound(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler, err error) error {
|
||||
if fsrv.PassThru {
|
||||
return next.ServeHTTP(w, r)
|
||||
}
|
||||
return caddyhttp.Error(http.StatusNotFound, nil)
|
||||
return caddyhttp.Error(http.StatusNotFound, err)
|
||||
}
|
||||
|
||||
// Indicates whether a file's modification time is useful for validator
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue