Skip to content

Commit 624e7b3

Browse files
committed
fix: HTTP method names should be uppercase
1 parent 2ca4ece commit 624e7b3

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

system/HTTP/IncomingRequest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,19 +383,19 @@ public function negotiate(string $type, array $supported, bool $strictMatch = fa
383383
*/
384384
public function is(string $value): bool
385385
{
386-
$value = strtolower($value);
386+
$valueUpper = strtoupper($value);
387387

388-
$httpMethods = ['get', 'post', 'put', 'delete', 'head', 'patch', 'options'];
388+
$httpMethods = ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'PATCH', 'OPTIONS'];
389389

390-
if (in_array($value, $httpMethods, true)) {
391-
return strtolower($this->getMethod()) === $value;
390+
if (in_array($valueUpper, $httpMethods, true)) {
391+
return strtoupper($this->getMethod()) === $valueUpper;
392392
}
393393

394-
if ($value === 'json') {
394+
if ($valueUpper === 'JSON') {
395395
return strpos($this->getHeaderLine('Content-Type'), 'application/json') !== false;
396396
}
397397

398-
if ($value === 'ajax') {
398+
if ($valueUpper === 'AJAX') {
399399
return $this->isAJAX();
400400
}
401401

tests/system/HTTP/IncomingRequestTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -624,19 +624,19 @@ public function testIsHTTPMethodLowerCase(string $value)
624624
{
625625
$request = $this->request->withMethod($value);
626626

627-
$this->assertTrue($request->is($value));
627+
$this->assertTrue($request->is(strtolower($value)));
628628
}
629629

630630
public function provideIsHTTPMethods(): Generator
631631
{
632632
yield from [
633-
['get'],
634-
['post'],
635-
['put'],
636-
['delete'],
637-
['head'],
638-
['patch'],
639-
['options'],
633+
['GET'],
634+
['POST'],
635+
['PUT'],
636+
['DELETE'],
637+
['HEAD'],
638+
['PATCH'],
639+
['OPTIONS'],
640640
];
641641
}
642642

@@ -645,7 +645,7 @@ public function provideIsHTTPMethods(): Generator
645645
*/
646646
public function testIsHTTPMethodUpperCase(string $value)
647647
{
648-
$request = $this->request->withMethod(strtoupper($value));
648+
$request = $this->request->withMethod($value);
649649

650650
$this->assertTrue($request->is($value));
651651
}

0 commit comments

Comments
 (0)