<cfheader>
Generates custom HTTP response headers to return to the client.
If <cfflush> has been used, the response is already committed and this will throw an error, unless you set throwOnError to false. In that case the header is skipped, no exception is thrown and a warning is written to the application log.
You can detect if a page has already been flushed using
getPageContext().getHttpServletResponse().isCommitted();
This tag's body/content and closing tag are optional.
This tag is also supported within <cfscript>
<cfheader
name=string
value=string
statusCode=number
charset=string
statusText=string
><!--- body --->[</cfheader>]
| Attribute | Description |
|---|---|
name
string, optional
|
edit
A name for the header. |
value
string, optional
|
edit
A value for the HTTP header. This attribute is used in conjunction with the name attribute. |
statusCode
number, optional
|
edit
A number that sets the HTTP status code. |
charset
string, optional
|
edit
The character encoding in which to encode the header value. For more information on character encodings, see: https://www.w3.org/International/questions/qa-html-encoding-declarations. |
statusText
string, optional
|
edit
Text that explains the status code. This attribute is used in conjunction with the statusCode attribute. |
Examples
edit<cfheader name="Content-Type" value="application/json">
Ignore a header set after the response was flushed
<cfflush>
<!--- the response is already committed, the header is skipped and a warning is logged --->
<cfheader name="X-Request-Id" value="abc" throwOnError="false">