From a1facc9fcb0d1e7a4cc093ec17460aa39f56b6dd Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 26 Nov 2023 00:11:22 +0100 Subject: [PATCH] Implement GH-12385: flush headers without body when calling flush() --- sapi/cgi/cgi_main.c | 10 ++++---- sapi/fpm/fpm/fpm_main.c | 7 ++++-- sapi/fpm/tests/gh12385.phpt | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 sapi/fpm/tests/gh12385.phpt diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 156599f6f9d4d..695a693019821 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -355,11 +355,11 @@ static void sapi_fcgi_flush(void *server_context) { fcgi_request *request = (fcgi_request*) server_context; - if ( - !parent && - request && !fcgi_flush(request, 0)) { - - php_handle_aborted_connection(); + if (!parent && request) { + sapi_send_headers(); + if (!fcgi_flush(request, 0)) { + php_handle_aborted_connection(); + } } } diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index b3ae2f69cc556..12709ae063ab9 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -291,8 +291,11 @@ static void sapi_cgibin_flush(void *server_context) /* {{{ */ /* fpm has started, let use fcgi instead of stdout */ if (fpm_is_running) { fcgi_request *request = (fcgi_request*) server_context; - if (!parent && request && !fcgi_flush(request, 0)) { - php_handle_aborted_connection(); + if (!parent && request) { + sapi_send_headers(); + if (!fcgi_flush(request, 0)) { + php_handle_aborted_connection(); + } } return; } diff --git a/sapi/fpm/tests/gh12385.phpt b/sapi/fpm/tests/gh12385.phpt new file mode 100644 index 0000000000000..08b9882616679 --- /dev/null +++ b/sapi/fpm/tests/gh12385.phpt @@ -0,0 +1,46 @@ +--TEST-- +GH-12385 (flush with fastcgi does not force headers to be sent) +--SKIPIF-- + +--FILE-- +start(); +$tester->expectLogStartNotices(); +$response = $tester->request(); +$response->expectHeader("X-Test", "12345"); +$response->expectBody("bool(true)"); +$tester->terminate(); +$tester->expectLogTerminatingNotices(); +$tester->close(); + +?> +Done +--EXPECT-- +Done +--CLEAN-- +