views:

61

answers:

2

The code

<cfheader name="Test" value="1">
<cfheader name="Test" value="2">

results in the header "Test: 2" being sent to the browser (as seen using HttpFox).

Is there a way for the second line of code to determine if a header with the same name has already been written using CFHEADER?

Thanks!

+3  A: 

Can't help with exact task of checking the headers, but I'd tried to implement the header facade to handle the headers sending and tracking the history of alredy processed items.

It can be as simple as UDF wrapper, like this one:

<!--- this should be somewhere on request start --->
<cfset request.headers = {} />

<!--- wrapper for cfheader --->
<cffunction name="SendHeader" returntype="void" output="false">
    <cfargument name="name" type="string" required="true" hint="Header name">
    <cfargument name="value" type="string" required="true" hint="Header value">
    <cfif NOT StructKeyExists(request.headers, arguments.name)>
        <cfset request.headers[arguments.name] = arguments.value />
        <cfheader name="#arguments.name#" value="#arguments.value#" />
    </cfif>
</cffunction>
Sergii
+10  A: 

What version of ColdFusion are you using? When I run your code on ColdFusion 9, I get the header value (As seen using FireBug):

test: 1, 2

As for whether or not you can tell what, if any, existing values there might be for the response header, I haven't yet found a way. I'll keep looking, though.

Update: Found it.

getPageContext().getResponse().containsHeader("test")

For example:

<cfif getPageContext().getResponse().containsHeader("test") eq "NO">
    <cfheader name="test" value="2" />
</cfif>
Adam Tuttle
Cool. Also works with Railo 3.1, including `test: 1, 2` output.
Sergii
Ah, we're using version ColdFusion Standard 8,0,1,195765, and LiveHTTPHeaders in Firefox shows just "Test: 2". Your code works perfectly on CF8 as well... will use that -- thanks!
Aidan Whitehall