|
 |
Adobe Dreamweaver Links
Adobe.com Dreamweaver Info |
Blogs
Blogger, Blogosphere, Web 2.0... |
Design Agencies
Adobe Dreamweaver Links |
Education And Training
Communicate, Help, Advertise... |
Flash Tutorials
Artists, Designers, Experts... |
Forums
Search, Learn, Communicate... |
Javascript Tutorials
Books, Help, Learning... |
News
Technology, Business, Web... |
|
|
|
How To Tell If A Header Has Been Set In ColdFusion
By Raymond Camden
Expert Author
Article Date: 2007-03-16
Here is an interesting question - how do you determine if something has been added to the response header?
I needed to know this because of an bug in ColdFire where cflocation stopped working when ColdFire was used.
Turns out that when you use cflocation, the debug template is still executed. I'm not sure why the template still runs - but when my code set information in the header, it apparently broke the data that cflocation had also set in the header. So obviously I needed to see if a cflocation header existed - and if so - suppress ColdFire. Easy, right?
Turns out it isn't that simple. ColdFusion provides a way to get request headers (getHTTPRequestData), but there is no built in way to get response headers. Luckily this is something built into the plumbing down in Java, and ColdFusion provides us a way to get there with getPageContext(). Consider the following code block:
<cfheader name="foo" value="1">
<cfset response = getPageContext().getResponse()>
<cfif response.containsHeader("foo")>
yes
<cfelse>
no
</cfif>
<p>
<cfif response.containsHeader("foo2")>
yes
<cfelse>
no
</cfif>
I set a header named foo. This is the header I'll be testing for. I then grab the page context object and from that grab the response object. How did I know to do this? I just looked around the Java API docs a bit. That is where I discovered that the response object has a "containsHeader" method that does exactly what it sounds like - returns true or false if the response contains a particular header.
If you find you need this functionality, try this simple UDF I wrote. (Which will be up on CFLib later today.)
<cfscript>
function responseHeaderExists(header) {
return getPageContext().getResponse().containsHeader(header);
}
</cfscript>
Comments
About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com
Raymond Camden is Vice President of Technology for roundpeg, Inc. A long
time ColdFusion user, Raymond has worked on numerous ColdFusion books
and is the creator of many of the most popular ColdFusion community web
sites. He is an Adobe Community Expert, user group manager, and the
proud father of three little bundles of joy.
|
|