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?
Header can be set using fluent syntax. from("direct:a") . setHeader("randomNumber"). simple("${random(1,100)}") .to("direct:b");
addHeader - simply adds the header to the response( doesn't overwrite the existing ones..) setHeader - clears all the existing ones( i.e with same header name) and adds the header to the response...
setHeader(name, value) (Added in v0. 4.0) method is an inbuilt application programming interface of the 'http' module which sets a single header value for implicit headers. If this header already exists in the to-be-sent headers, its value will be replaced.
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'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With