MCPcopy
hub / github.com/caddyserver/caddy / funcHTTPError

Method funcHTTPError

modules/caddyhttp/templates/tplcontext.go:455–465  ·  modules/caddyhttp/templates/tplcontext.go::TemplateContext.funcHTTPError

funcHTTPError returns a structured HTTP handler error. EXPERIMENTAL; SUBJECT TO CHANGE. Example usage: `{{if not (fileExists $includeFile)}}{{httpError 404}}{{end}}`

(statusCode int)

Source from the content-addressed store, hash-verified

453// funcHTTPError returns a structured HTTP handler error. EXPERIMENTAL; SUBJECT TO CHANGE.
454// Example usage: `{{if not (fileExists $includeFile)}}{{httpError 404}}{{end}}`
455func (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//

Callers

nothing calls this directly

Calls 2

ErrorFunction · 0.92
DelMethod · 0.80

Tested by

no test coverage detected