Skip to content

Commit

Permalink
feat(Req): getHeader 支持键名包含 -,如 Access-Control-Request-Method
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Mar 31, 2024
1 parent 0873253 commit 6436091
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Req.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ protected function hasHeader(string $name): bool
*/
protected function getHeader(string $name): ?string
{
$name = 'HTTP_' . strtoupper($name);
$name = 'HTTP_' . strtoupper(strtr($name, '-', '_'));
return $this->servers[$name] ?? null;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/ReqTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1153,12 +1153,14 @@ public function testGetHeaderAndHasHeader()
'servers' => [
'HTTP_ORIGIN' => 'https://test.com',
'HTTP_TEST' => 'test',
'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'GET',
'ORIGIN' => 'https://test2.com',
],
]);
$this->assertSame('https://test.com', $req->getHeader('ORIGIN'));
$this->assertSame('https://test.com', $req->getHeader('origin'));
$this->assertSame('test', $req->getHeader('test'));
$this->assertSame('GET', $req->getHeader('Access-Control-Request-Method'));
$this->assertNull($req->getHeader('test2'));

$this->assertTrue($req->hasHeader('ORIGIN'));
Expand Down

0 comments on commit 6436091

Please sign in to comment.