@marcel91200 / caddy Mirror · read-only / commits / 4e8245df
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, 22:00 UTC

templates: Delete headers on `httpError` to reset to clean slate (#5905)

Francis Lavoie committed Oct 18, 2023 at 18:43 UTC 4e8245df0b289007e84f42212977ea0bd27826d5
1 file changed +8
modules/caddyhttp/templates/tplcontext.go
+8
@@ -444,6 +444,14 @@ func (c TemplateContext) funcFileStat(filename string) (fs.FileInfo, error) {
444 // funcHTTPError returns a structured HTTP handler error. EXPERIMENTAL; SUBJECT TO CHANGE.
445 // Example usage: `{{if not (fileExists $includeFile)}}{{httpError 404}}{{end}}`
446 func (c TemplateContext) funcHTTPError(statusCode int) (bool, error) {
447 + // Delete some headers that may have been set by the underlying
448 + // handler (such as file_server) which may break the error response.
449 + c.RespHeader.Header.Del("Content-Length")
450 + c.RespHeader.Header.Del("Content-Type")
451 + c.RespHeader.Header.Del("Etag")
452 + c.RespHeader.Header.Del("Last-Modified")
453 + c.RespHeader.Header.Del("Accept-Ranges")
454 +
455 return false, caddyhttp.Error(statusCode, nil)
456 }
457