In another post, I wrote about how you can replicate the functionality of cfcontent’s “reset” attribute in CFScript.  The other day, I came across a related issue of needing to be able to do the same thing (all code in CFScript, that is) for cfheader.  Fortunately, by using the same approaching of tapping into the underlying Java methods, this is extremely easy.

Setting Status

To set the status code for the page request, simply do the following:

pc = getpagecontext().getresponse();

No big deal there.  Also, be aware that the setstatus() method can take an optional second string attribute, so if you wish to define a message to accompanying the status code, feel free :)

Setting Headers

Honestly, I use headers in CF mostly for downloading files, or returning certain content types.  Just as with setting the status, it’s pretty freaking simply to do in CFScript:

pc = getpagecontext().getresponse();