Skip to content

Commit

Permalink
Support using numeric headers (#34)
Browse files Browse the repository at this point in the history
Support using numeric header values without having type errors. An example use case would be the usage of the `Content-Length` header, which might be set with the result of a call to `strlen`.
  • Loading branch information
iambrosi authored and Nyholm committed Apr 14, 2018
1 parent b27762f commit ac741e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/MessageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private function setHeaders(array $headers): void
*/
private function trimHeaderValues(array $values): array
{
return array_map(function ($value) {
return array_map(function (string $value) {
return trim($value, " \t");
}, $values);
}
Expand Down
9 changes: 9 additions & 0 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ public function testAggregatesHeaders()
$this->assertEquals('zoobar, foobar, zoobar', $r->getHeaderLine('zoo'));
}

public function testSupportNumericHeaders()
{
$r = new Request('GET', '', [
'Content-Length' => 200,
]);
$this->assertSame(['Content-Length' => ['200']], $r->getHeaders());
$this->assertSame('200', $r->getHeaderLine('Content-Length'));
}

public function testAddsPortToHeader()
{
$r = new Request('GET', 'http://foo.com:8124/bar');
Expand Down

0 comments on commit ac741e4

Please sign in to comment.