Fix GH-9981: FPM does not reset fastcgi.error_header

This commit is contained in:
Jakub Zelenka 2022-12-22 18:32:16 +00:00
parent 29926c3262
commit a3891d9d1a
No known key found for this signature in database
GPG Key ID: 1C0779DC5C0A9DE4
4 changed files with 88 additions and 0 deletions

4
NEWS
View File

@ -13,6 +13,10 @@ PHP NEWS
. Fixed bug GH-9891 (DateTime modify with unixtimestamp (@) must work like
setTimestamp). (Derick)
- FPM:
. Fixed bug GH-9981 (FPM does not reset fastcgi.error_header).
(Jakub Zelenka)
- LDAP:
. Fixed bug GH-10112 (LDAP\Connection::__construct() refers to ldap_create()).
(cmb)

View File

@ -1911,6 +1911,9 @@ consult the installation file that came with this distribution, or visit \n\
fpm_request_executing();
/* Reset exit status from the previous execution */
EG(exit_status) = 0;
php_execute_script(&file_handle);
fastcgi_request_done:

View File

@ -0,0 +1,51 @@
--TEST--
FPM: gh9981 - fastcgi.error_header is not reset
--SKIPIF--
<?php
include "skipif.inc"; ?>
--FILE--
<?php
require_once "tester.inc";
$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
[unconfined]
listen = {{ADDR}}
pm = static
pm.max_children = 1
catch_workers_output = yes
EOT;
$code = <<<EOT
<?php
if (isset(\$_GET['q'])) {
echo 'ok';
} else {
d();
}
EOT;
$tester = new FPM\Tester($cfg, $code);
$tester->start(iniEntries: [
'fastcgi.error_header' => '"HTTP/1.1 500 PHP Error"',
'output_buffering' => 4096,
]);
$tester->expectLogStartNotices();
$tester->request()->expectStatus('500 PHP Error');
$tester->request('q=1')->expectNoStatus();
$tester->terminate();
$tester->expectLogTerminatingNotices();
$tester->expectNoLogPattern('/Cannot modify header information/');
$tester->close();
?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>

View File

@ -134,6 +134,36 @@ class Response
return $this;
}
/**
* Expect response status.
*
* @param string|null $status Expected status.
*
* @return Response
*/
public function expectStatus(string|null $status): Response {
$headers = $this->getHeaders();
if (is_null($status) && !isset($headers['status'])) {
return $this;
}
if (!is_null($status) && !isset($headers['status'])) {
$this->error('Status is expected but not supplied');
} elseif ($status !== $headers['status']) {
$statusMessage = $status === null ? "expected not to be set": "expected to be $status";
$this->error("Status is $statusMessage but the actual value is {$headers['status']}");
}
return $this;
}
/**
* Expect response status not to be set.
*
* @return Response
*/
public function expectNoStatus(): Response {
return $this->expectStatus(null);
}
/**
* Expect no error in the response.
*