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: 184.108.40.206
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.