开发者

Can CFHEADER values be read by other code?

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!


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>


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜