From ae969ecd39e9fb157cd72f6049016a50ee07ec52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 26 Aug 2019 12:39:40 -0300 Subject: [PATCH] Set the correct HTTP response code for the router MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sets the correct HTTP response code when the route path is not found or the requested method is not allowed. Signed-off-by: MaurĂ­cio Meneghini Fauth --- index.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 36ba76d13e..4f5c2d40cd 100644 --- a/index.php +++ b/index.php @@ -9,6 +9,7 @@ declare(strict_types=1); use FastRoute\Dispatcher; use PhpMyAdmin\Message; +use PhpMyAdmin\Response; use function FastRoute\simpleDispatcher; @@ -16,7 +17,7 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -global $route; +global $containerBuilder, $route; require_once ROOT_PATH . 'libraries/common.inc.php'; @@ -41,11 +42,17 @@ $routeInfo = $dispatcher->dispatch( rawurldecode($route) ); if ($routeInfo[0] === Dispatcher::NOT_FOUND) { + /** @var Response $response */ + $response = $containerBuilder->get(Response::class); + $response->setHttpResponseCode(404); Message::error(sprintf( __('Error 404! The page %s was not found.'), '' . ($route) . '' ))->display(); } elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) { + /** @var Response $response */ + $response = $containerBuilder->get(Response::class); + $response->setHttpResponseCode(405); Message::error(__('Error 405! Request method not allowed.'))->display(); } elseif ($routeInfo[0] === Dispatcher::FOUND) { $handler = $routeInfo[1];