cause...">

Is it possible to read CFHEADER values ​​with different code?

Code

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

causes the heading "Test: 2" to be sent to the browser (as seen from 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?

Thank!

+5
source share
2 answers

What version of ColdFusion are you using? When I run my code in ColdFusion 9, I get the header value (as seen using FireBug ):

test: 1, 2

As for whether you can tell what, if any, existing values ​​for the response header, I have not yet found a way. However, I will continue to search.

: .

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

:

<cfif getPageContext().getResponse().containsHeader("test") eq "NO">
    <cfheader name="test" value="2" />
</cfif>
+12

, , alredy.

, UDF, :

<!--- 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>
+3

All Articles