@marcel91200 / caddy Mirror · read-only / commits / a8492c06
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 23:15 UTC

fileserver: Don't repeat error for invalid method inside error context (#5705)

Francis Lavoie committed Aug 9, 2023 at 13:12 UTC a8492c064df48bb1b2830fb82cf740cfeba4b2b2
1 file changed +7 -2
modules/caddyhttp/fileserver/staticfiles.go
+7 -2
@@ -418,8 +418,13 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
418 // GET and HEAD, which is sensible for a static file server - reject
419 // any other methods (see issue #5166)
420 if r.Method != http.MethodGet && r.Method != http.MethodHead {
421 - w.Header().Add("Allow", "GET, HEAD")
422 - return caddyhttp.Error(http.StatusMethodNotAllowed, nil)
421 + // if we're in an error context, then it doesn't make sense
422 + // to repeat the error; just continue because we're probably
423 + // trying to write an error page response (see issue #5703)
424 + if _, ok := r.Context().Value(caddyhttp.ErrorCtxKey).(error); !ok {
425 + w.Header().Add("Allow", "GET, HEAD")
426 + return caddyhttp.Error(http.StatusMethodNotAllowed, nil)
427 + }
428 }
429
430 // set the Etag - note that a conditional If-None-Match request is handled