Skip to content

Commit 439bcdf

Browse files
authored
Merge pull request #2012 from MGatner/routes-respect-spoofs
Use request->method for HTTP verb
2 parents 063a53e + a538fcf commit 439bcdf

3 files changed

Lines changed: 52 additions & 50 deletions

File tree

system/CodeIgniter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,12 +986,13 @@ public function storePreviousURL($uri)
986986
* Modifies the Request Object to use a different method if a POST
987987
* variable called _method is found.
988988
*
989-
* Does not work on CLI commands.
990989
*/
991990
public function spoofRequestMethod()
992991
{
992+
// CLI commands always use 'cli' method
993993
if (is_cli())
994994
{
995+
$this->request->setMethod('cli');
995996
return;
996997
}
997998

system/Router/RouteCollection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
namespace CodeIgniter\Router;
4141

42+
use Config\Services;
4243
use CodeIgniter\Autoloader\FileLocator;
4344
use CodeIgniter\Router\Exceptions\RouterException;
4445

@@ -233,8 +234,8 @@ class RouteCollection implements RouteCollectionInterface
233234
*/
234235
public function __construct(FileLocator $locator, $moduleConfig)
235236
{
236-
// Get HTTP verb
237-
$this->HTTPVerb = strtolower($_SERVER['REQUEST_METHOD'] ?? 'cli');
237+
// Get HTTP verb from current request (accounts for spoofing)
238+
$this->HTTPVerb = Services::request()->getMethod();
238239

239240
$this->fileLocator = $locator;
240241

@@ -1115,7 +1116,7 @@ public function reverseRoute(string $search, ...$params)
11151116
{
11161117
$from = key($route['route']);
11171118
$to = $route['route'][$from];
1118-
1119+
11191120
// ignore closures
11201121
if (! is_string($to))
11211122
{

0 commit comments

Comments
 (0)