How can I get setHeader to overwrite an existing header?

I'm working on a CF interface to the ChromeLogger extension (shameless plug), which uses HTTP headers to log data from a server side language to the Chrome console.

Over the course of a request, the log() method can be called multiple times. For each call, I am writing the header in the format that ChromeLogger needs to display the data correctly. In CF10, this works fine - each subsequent call to setHeader() overwrites the previously set header with the same name. In CF9, however, I am seeing multiple headers with the same name.

This sample code demonstrates the issue:

<cfscript>
pc = getPageContext().getResponse();
pc.setHeader( "test-header", "value 1" );
pc.setHeader( "test-header", "value 2" );
pc.setHeader( "test-header", "value 3" );
</cfscript>

In CF9, I see three headers named "test-header," each with their own value. In CF10, I see one header named "test-header," with a value of "value 3." According to the Java docs for this method, the latter is correct (emphasis mine):

Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one . The containsHeader method can be used to test for the presence of a header before setting its value.

Using the cfheader tag has the same results, presumably because it just wraps the setHeader() method.

I'm aware that I can build up the header over the course of the request and then call setHeader() one time at the end via onRequestEnd() , but I'd like this component to be as self-contained as possible - the less the end user has to modify their code to implement it, the better.

Is there any other way in CF9 to overwrite an existing header?


Looks like it could be a bug in ColdFusion 9. https://bugbase.adobe.com/index.cfm?event=bug&id=3041696 This bug was entered by Adam Cameron back in June 2010 for version 9.0 (as far as I can tell). It is listed with a status of 'Deferred' and reason of 'NotEnoughTime'.

链接地址: http://www.djcxy.com/p/12850.html

上一篇: 在域外使用AD登录详细信息验证SQL连接

下一篇: 我怎样才能让setHeader覆盖现有的头文件?