summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2023-08-09 13:12:09 -0400
committerGitHub <noreply@github.com>2023-08-09 17:12:09 +0000
commita8492c064df48bb1b2830fb82cf740cfeba4b2b2 (patch)
treef6e5def83bd2b38366f8d8d9d872777d85281363 /modules
parent6cdcc2a78208b1d30b37fb06780160fcad48aab4 (diff)
fileserver: Don't repeat error for invalid method inside error context (#5705)
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/fileserver/staticfiles.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go
index 3261093..133578c 100644
--- a/modules/caddyhttp/fileserver/staticfiles.go
+++ b/modules/caddyhttp/fileserver/staticfiles.go
@@ -418,8 +418,13 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
// GET and HEAD, which is sensible for a static file server - reject
// any other methods (see issue #5166)
if r.Method != http.MethodGet && r.Method != http.MethodHead {
- w.Header().Add("Allow", "GET, HEAD")
- return caddyhttp.Error(http.StatusMethodNotAllowed, nil)
+ // if we're in an error context, then it doesn't make sense
+ // to repeat the error; just continue because we're probably
+ // trying to write an error page response (see issue #5703)
+ if _, ok := r.Context().Value(caddyhttp.ErrorCtxKey).(error); !ok {
+ w.Header().Add("Allow", "GET, HEAD")
+ return caddyhttp.Error(http.StatusMethodNotAllowed, nil)
+ }
}
// set the Etag - note that a conditional If-None-Match request is handled