diff --git a/.github/docker/ci/lib.sh b/.github/docker/ci/lib.sh index bdd06656bc..dd122e76c5 100644 --- a/.github/docker/ci/lib.sh +++ b/.github/docker/ci/lib.sh @@ -88,8 +88,8 @@ http_check() { php -r ' // The front end and the manager are the two entry points an installed - // site has to serve. The manager answers 404 without an Accept-Language - // header by design, hence the header on the second request. + // site has to serve. The manager request carries no Accept-Language + // header on purpose: the manager must fall back to English. $port = $argv[1]; $expect = $argv[2]; $get = function (string $path, array $headers = []) use ($port): array { @@ -125,7 +125,7 @@ http_check() { $failures[] = "the front page rendered nothing"; } - [$status, $body] = $get("/manager/index.php", ["Accept-Language: en-US,en;q=0.9"]); + [$status, $body] = $get("/manager/index.php"); echo "manager: {$status}\n"; $status === 200 or $failures[] = "the manager answered {$status}"; stripos($body, "password") !== false or $failures[] = "the manager did not render its login form"; diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fb5cacc45d..b2a3cf56d4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -114,8 +114,8 @@ jobs: curl -sf -o /dev/null http://127.0.0.1:8899/ && break done front=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8899/) - # The manager answers 404 without an Accept-Language header by design. - manager=$(curl -s -o /dev/null -w '%{http_code}' -H 'Accept-Language: en-US,en;q=0.9' http://127.0.0.1:8899/manager/index.php) + # No Accept-Language header on purpose: the manager must default to English. + manager=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8899/manager/index.php) echo "front=$front manager=$manager" test "$front" = "200" && test "$manager" = "200" @@ -285,8 +285,8 @@ jobs: curl -sf -o /dev/null http://127.0.0.1:8899/ && break done front=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8899/) - # The manager answers 404 without an Accept-Language header by design. - manager=$(curl -s -o /dev/null -w '%{http_code}' -H 'Accept-Language: en-US,en;q=0.9' http://127.0.0.1:8899/manager/index.php) + # No Accept-Language header on purpose: the manager must default to English. + manager=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8899/manager/index.php) # A friendly URL has to be routed into index.php rather than answered # by the web server itself. Whether the CMS then renders a page or an # error is not the point — reaching PHP at all is — so this looks for diff --git a/core/tests/Unit/Manager/ManagerAcceptLanguageDefaultTest.php b/core/tests/Unit/Manager/ManagerAcceptLanguageDefaultTest.php new file mode 100644 index 0000000000..8b648822ca --- /dev/null +++ b/core/tests/Unit/Manager/ManagerAcceptLanguageDefaultTest.php @@ -0,0 +1,41 @@ +not->toMatch('/if\s*\(\s*!\s*isset\(\$_SERVER\[\'HTTP_ACCEPT_LANGUAGE\'\]\)\s*\)\s*\{\s*header\([^)]*404/'); +}); + +it('defaults a missing Accept-Language header to English', function () { + $statement = managerAcceptLanguageDefaultStatement(); + expect($statement)->not->toBe(''); + + $backup = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? null; + try { + unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); + eval($statement); + expect($_SERVER['HTTP_ACCEPT_LANGUAGE'])->toBe('en'); + + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-DE,de;q=0.9'; + eval($statement); + expect($_SERVER['HTTP_ACCEPT_LANGUAGE'])->toBe('de-DE,de;q=0.9'); + } finally { + if ($backup === null) { + unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); + } else { + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $backup; + } + } +}); diff --git a/manager/index.php b/manager/index.php index b951eddf4d..7c1ffe3c39 100755 --- a/manager/index.php +++ b/manager/index.php @@ -96,10 +96,8 @@ exit; } -if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { - header('HTTP/1.0 404 Not Found'); - exit; -} +// Clients that send no Accept-Language header (API clients, health checks) get English. +$_SERVER['HTTP_ACCEPT_LANGUAGE'] ??= 'en'; // send anti caching headers header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');