Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Handle request headers with numeric keys #286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ServerRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ public static function marshalHeaders(array $server)

if ($value && strpos($key, 'HTTP_') === 0) {
$name = strtr(strtolower(substr($key, 5)), '_', '-');
$headers[$name] = $value;

if (! is_numeric($name)) {
$headers[$name] = $value;
}

continue;
}

Expand Down
1 change: 1 addition & 0 deletions test/ServerRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function testMarshalsExpectedHeadersFromServerArray()
'HTTP_CONTENT_TYPE' => 'application/json',
'HTTP_ACCEPT' => 'application/json',
'HTTP_X_FOO_BAR' => 'FOOBAR',
'HTTP__1' => '-1',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on RFC 7230, this should be interpreted as the following header:

-1: -1

since - and numeric characters are all valid for header names. As such, this test is not correct.

I just added the above to the current test suite, and then updated the $expected value to include a '-1' => '-1' case, and it passes as expected.

'CONTENT_MD5' => 'CONTENT-MD5',
'CONTENT_LENGTH' => 'UNSPECIFIED',
];
Expand Down