mirror of https://github.com/caddyserver/caddy.git
fileserver: Don't repeat error for invalid method inside error context (#5705)
This commit is contained in:
parent
6cdcc2a782
commit
a8492c064d
|
@ -418,9 +418,14 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
||||||
// GET and HEAD, which is sensible for a static file server - reject
|
// GET and HEAD, which is sensible for a static file server - reject
|
||||||
// any other methods (see issue #5166)
|
// any other methods (see issue #5166)
|
||||||
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||||
|
// 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")
|
w.Header().Add("Allow", "GET, HEAD")
|
||||||
return caddyhttp.Error(http.StatusMethodNotAllowed, nil)
|
return caddyhttp.Error(http.StatusMethodNotAllowed, nil)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set the Etag - note that a conditional If-None-Match request is handled
|
// set the Etag - note that a conditional If-None-Match request is handled
|
||||||
// by http.ServeContent below, which checks against this Etag value
|
// by http.ServeContent below, which checks against this Etag value
|
||||||
|
|
Loading…
Reference in New Issue