funcHTTPError returns a structured HTTP handler error. EXPERIMENTAL; SUBJECT TO CHANGE. Example usage: `{{if not (fileExists $includeFile)}}{{httpError 404}}{{end}}`
(statusCode int)
| 453 | // funcHTTPError returns a structured HTTP handler error. EXPERIMENTAL; SUBJECT TO CHANGE. |
| 454 | // Example usage: `{{if not (fileExists $includeFile)}}{{httpError 404}}{{end}}` |
| 455 | func (c TemplateContext) funcHTTPError(statusCode int) (bool, error) { |
| 456 | // Delete some headers that may have been set by the underlying |
| 457 | // handler (such as file_server) which may break the error response. |
| 458 | c.RespHeader.Header.Del("Content-Length") |
| 459 | c.RespHeader.Header.Del("Content-Type") |
| 460 | c.RespHeader.Header.Del("Etag") |
| 461 | c.RespHeader.Header.Del("Last-Modified") |
| 462 | c.RespHeader.Header.Del("Accept-Ranges") |
| 463 | |
| 464 | return false, caddyhttp.Error(statusCode, nil) |
| 465 | } |
| 466 | |
| 467 | // funcHumanize transforms size and time inputs to a human readable format. |
| 468 | // |