frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

"the current responseWriter is not a flusher" when using X-Accel-Redirect

Open aleho opened this issue 8 months ago • 6 comments

Implementing X-Accel-Redirect with this simple config:

request_header X-Sendfile-Type x-accel-redirect
request_header X-Accel-Mapping /private-files=

intercept {
	@accel header X-Accel-Redirect *
	handle_response @accel {
		root    * /private-files
		rewrite * {resp.header.X-Accel-Redirect}
		method  * GET

		header -X-Accel-Redirect
		header -X-Accel-Buffering

		file_server
	}
}

php_server

Each response produces this error output: ERROR frankenphp the current responseWriter is not a flusher {"error": "feature not supported"}

Can anyone confirm / reproduce that?

FrankenPHP: v2.10.0 h1:fonubSaQKF1YANl8TXqGcn4IbIRUDdfAkpcsfI/vX5U=

Originally posted by @aleho in https://github.com/dunglas/frankenphp/issues/896#issuecomment-2687214121

aleho avatar May 06 '25 11:05 aleho

Yeah seems like the error is produced here when trying to flush the response and send it to the client. I'm assuming the intercepted responses cannot be flushed like that.

Is it only logging the error or is the response generally broken?

AlliBalliBaba avatar May 07 '25 16:05 AlliBalliBaba

It happens for every request, so also those that are not intercepted at all.

The response seems to work though.

aleho avatar May 07 '25 17:05 aleho

In that case it might also be fine to change this to a debug message. Are you explicitly sending the response to the client anywhere in your code? You just would need to consider that sending the response before execution is finished wouldn't work here, the response will probably always get sent at the end of script execution.

AlliBalliBaba avatar May 07 '25 19:05 AlliBalliBaba

Or actually, I tried the intercept configuration that you provided and couldn't reproduce the error. Could you share your whole Caddyfile or create a minimal reproducer? Are you using the Docker image or the official static binary?

AlliBalliBaba avatar May 07 '25 20:05 AlliBalliBaba

Did you try with worker mode or php / php_server?

My whole Caddyfile is a bit much to share because it's distracting.

I tried with https://github.com/dunglas/symfony-docker and can reproduce the output with the following patch:

diff --git a/frankenphp/Caddyfile b/frankenphp/Caddyfile
index 43d3ea7..d1ffdf5 100644
--- a/frankenphp/Caddyfile
+++ b/frankenphp/Caddyfile
@@ -4,11 +4,11 @@
 	frankenphp {
 		{$FRANKENPHP_CONFIG}
 
-		worker {
-			file ./public/index.php
-			env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime
-			{$FRANKENPHP_WORKER_CONFIG}
-		}
+		#worker {
+		#	file ./public/index.php
+		#	env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime
+		#	{$FRANKENPHP_WORKER_CONFIG}
+		#}
 	}
 }
 
@@ -54,6 +54,23 @@
 	}
 	rewrite @phpRoute index.php
 
+	request_header X-Sendfile-Type x-accel-redirect
+	request_header X-Accel-Mapping ../private-files=/private-files
+
+	intercept {
+		@sendfile header X-Accel-Redirect *
+		handle_response @sendfile {
+			root    private-files/
+			rewrite * {resp.header.X-Accel-Redirect}
+			method  * GET
+
+			header -X-Accel-Redirect
+			header -X-Accel-Buffering
+
+			file_server
+		}
+	}
+
 	@frontController path index.php
 	php @frontController
 

aleho avatar May 08 '25 08:05 aleho

Oh I was able to reproduce it, the error only gets logged when responding through HTTP2 + HTTPS. I think it should be fine to make this a debug message

AlliBalliBaba avatar May 09 '25 16:05 AlliBalliBaba