mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
templates: Delete headers on httpError
to reset to clean slate (#5905)
This commit is contained in:
parent
ac1f20b9e4
commit
4e8245df0b
1 changed files with 8 additions and 0 deletions
|
@ -444,6 +444,14 @@ func (c TemplateContext) funcFileStat(filename string) (fs.FileInfo, error) {
|
||||||
// funcHTTPError returns a structured HTTP handler error. EXPERIMENTAL; SUBJECT TO CHANGE.
|
// funcHTTPError returns a structured HTTP handler error. EXPERIMENTAL; SUBJECT TO CHANGE.
|
||||||
// Example usage: `{{if not (fileExists $includeFile)}}{{httpError 404}}{{end}}`
|
// Example usage: `{{if not (fileExists $includeFile)}}{{httpError 404}}{{end}}`
|
||||||
func (c TemplateContext) funcHTTPError(statusCode int) (bool, error) {
|
func (c TemplateContext) funcHTTPError(statusCode int) (bool, error) {
|
||||||
|
// Delete some headers that may have been set by the underlying
|
||||||
|
// handler (such as file_server) which may break the error response.
|
||||||
|
c.RespHeader.Header.Del("Content-Length")
|
||||||
|
c.RespHeader.Header.Del("Content-Type")
|
||||||
|
c.RespHeader.Header.Del("Etag")
|
||||||
|
c.RespHeader.Header.Del("Last-Modified")
|
||||||
|
c.RespHeader.Header.Del("Accept-Ranges")
|
||||||
|
|
||||||
return false, caddyhttp.Error(statusCode, nil)
|
return false, caddyhttp.Error(statusCode, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue