ColdBox and changing content headers in script
Tags: ColdFusion 9, Coldbox
Recently I needed the ability to set response headers in script, previously I had just used the layout to use the tag version. Now although it isn't anything new and we have been able to do this in ColdFusion since the days ColdFusion was written in Java, if not earlier, I thought I would share what I was trying to achieve and provide a better insight to the possibilities.
Sometime ago a question was asked in the ColdBox mailing list, on whether it was possible to achieve something like FaceBook's big pipe. The solution is not easy, due to the nature of ColdBox and I am still working on a solution there. However I did require the ability to change the header content, so that some pages could be cached by the browser and others would not be cached.
The solution was to delve into the response information provided by ColdFusion, which would be the following code to get the response.
Now with that in mind I can then go and write something like this.
response = getPageContext().getResponse();
response.setHeader('Cache-Control', 'no-cache');
response.addDateHeader('Expires', 0);
response.setDateHeader('max-age', 0);
response.setIntHeader ('Expires', -1);
response.addHeader('cache-Control', 'private');
response.addHeader('cache-Control', 'no-store');
response.addHeader('cache-Control', 'must-revalidate');
}
Simple enough, and now anytime a controller needs to send a view that requires not to be cached, I can just call this prior to the controller ending.
With my original problem, for some reason when trying to achieve flushing. I found that the browser was never receiving the right header information to accept a flush from the server, again this was solved by using a simialr approach to the above, but to use the Transfer-Encoding: chunked in the header instead.
Which then allowed for the content to be flushed via ColdFusion in script, inside ColdBox is a different story because the views are all built then sent to the browser in a large chunk. So to overcome this, one has to write a special renderer that would allow for the content to be piped like FaceBook.
As you can see for those in the know, I am not doing anything that has not been around for sometime. However I did find myself trying to find information on how to do this in ColdBox with little success.
There are no comments for this entry.



TweetBacks