Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/caddyhttp/fileserver/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,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)
}
Expand Down
12 changes: 6 additions & 6 deletions modules/caddyhttp/fileserver/staticfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,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) {
Expand Down Expand Up @@ -371,7 +371,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
Expand All @@ -383,7 +383,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
Expand Down Expand Up @@ -501,7 +501,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
}
Expand Down Expand Up @@ -730,11 +730,11 @@ func fileHidden(filename string, hide []string) bool {

// 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
Expand Down
Loading