Anyone ever run into this one when using cfheader ...
# lucee
s
Anyone ever run into this one when using cfheader in Lucee 5.4?
can't assign value to header, header is already committed
This is the line in question and it only happened once and is hard to reproduce:
header name="Access-Control-Allow-Credentials" value="true";
m
I have seen that issue more than once, but I haven't figured out what triggers it.
s
It's an uploader endpoint, and so it can often be called in a batch, with several requests to that endpoint firing concurrently, and I wondered if that had something to do with it
j
I've seen this when you use <cfflush> to stream the response
You can check for that situation with code like this:
Copy code
var flushed = getPageContext().getResponse().isCommitted();
if( !flushed ) {
	cfheader( name= "content-type", value= request.contentType );
}
s
Interesting, this is via FW/1 rendering JSON but it's possible the framework is doing a flush
Looks like a good fix to put in place, regardless
m
Like Jordan, I've seen it with a flush, and when there was enough content that cf forced a flush
s
Thanks for the heads up. It's a bit strange in this case, even though uploads can certainly be large, the output is a single json element:
{"location": "<href>"}
so I wouldn't expect there to be so much content that it forced a flush, unless there was perhaps an error upstream that was already being flushed before the preprocessing handler (before) of the controller, which is where the cfheader was.
g
cfflush is sending what it has in its output stream to the client already, good for streaming stuff. This means the header is gone. CFLocation for example tries to rewrite the header which is already flushed. Same is with any other thing like a CFContent or similar. HTH