I’ve migrated a site from CF to Lucee. I have a page that is running a CFEXECUTE command. Once it’s run, I then run a CFLOCATION to revert the user to a previous page.
I get the error Response Buffer is already flushed when running the CFLOCATION command. Here is the CFML:
I’m using this sort of command structure throughout this site (e.g. CFLOCATION tags with fueseactions, variables and messages that are then displayed on the forwarded page), so am not sure why this error should occur against this type of command.
Any ideas appreciated! Thanks.
OS: Windows Server 2022 Standard Java Version: 11.0.18 (Eclipse Adoptium) 64 bit Tomcat Version: 9.0.71 Lucee Version: 5.3.10.120
Cfexecute is an interaction between ColdFusion and the Operating System. So, it just might be that cfexecute and cflocation are not working well together.
What about using a named lock to synchronize them? For example, by doing something like the following:
lock name=“uniqueLockName68264” {
// the cfexecute code
}
lock name=“uniqueLockName68264” {
// the cflocation code
}
OK. Am afraid that does not make much sense to me, but what I take away from this is that I was correct in thinking that it was an earlier CFEXECUTE that is causing a problem further on in the page. Right?
For now, I’ve added an outputfile argument to the CFEXECUTE and will report back if this fixes it.
For cflocation to work, the server must send an HTTP location header to the browser. As the name implies, headers are the first thing to be returned by the server, before the actual response body is returned to the browser.
Lucee (like most other servlets) uses an output buffer that captures the output generated by your page and returns this output to the browser each time the buffer is full.
A common buffer size would be 1024 bytes, for example (I don’t know the actual default output buffer size used by Lucee).
When the buffer is full, the headers are sent to the browser (if they haven’t already been sent), followed by the buffer content.
This means that cflocation can only be used before Lucee’s output buffer has been filled and flushed for the first time. That’s because at that point, the headers are sent to the browser and there is no way to change the headers after the fact by your cflocation invocation.
So basically you need to call cflocation before too much output (even whitespace) has been generated by your page.
That’s why Zack suggested using cfsilent for the code preceding your cflocation call or using the variable attribute in order to prevent cfexecute’s output from being appended to the output buffer.
Hope this helps.