mirror of
https://github.com/caddyserver/caddy.git
synced 2025-03-23 05:49:27 +01:00
* fileserver: Reject non-GET/HEAD requests (close #5166) * Set Allow header according to RFC 9110 10.2.1
This commit is contained in:
parent
4bf6cb4199
commit
a3ae146cbd
1 changed files with 8 additions and 0 deletions
|
@ -410,6 +410,14 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
||||||
etag = calculateEtag(info)
|
etag = calculateEtag(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// at this point, we're serving a file; Go std lib supports only
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
w.Header().Set("Etag", etag)
|
w.Header().Set("Etag", etag)
|
||||||
|
|
Loading…
Reference in a new issue