diff --git a/Route.php b/Route.php index 67aaeb9..1773e0f 100644 --- a/Route.php +++ b/Route.php @@ -93,12 +93,10 @@ class Route { if (!$route_match_found) { // But a matching path exists if ($path_match_found) { - header('HTTP/1.0 405 Method Not Allowed'); if (self::$methodNotAllowed) { call_user_func_array(self::$methodNotAllowed, Array($path,$method)); } } else { - header('HTTP/1.0 404 Not Found'); if (self::$pathNotFound) { call_user_func_array(self::$pathNotFound, Array($path)); } diff --git a/index.php b/index.php index 0e954f2..ff784e5 100644 --- a/index.php +++ b/index.php @@ -125,6 +125,10 @@ Route::add('/this-route-is-defined', function() { // Add a 404 not found route Route::pathNotFound(function($path) { + // Do not forget to send a status header back to the client + // The router will not send any headers by default + // So you will have the full flexibility to handle this case + header('HTTP/1.0 404 Not Found'); navi(); echo 'Error 404 :-(
'; echo 'The requested path "'.$path.'" was not found!'; @@ -132,6 +136,10 @@ Route::pathNotFound(function($path) { // Add a 405 method not allowed route Route::methodNotAllowed(function($path, $method) { + // Do not forget to send a status header back to the client + // The router will not send any headers by default + // So you will have the full flexibility to handle this case + header('HTTP/1.0 405 Method Not Allowed'); navi(); echo 'Error 405 :-(
'; echo 'The requested path "'.$path.'" exists. But the request method "'.$method.'" is not allowed on this path!';