Skip to content

Commit

Permalink
Fix POST bug with case-insensitive header detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed May 14, 2018
1 parent 38b1b2d commit 6f1d955
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Bridge/Psr7/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function fromLambdaEvent(array $event) : ServerRequestInterface
// TODO Parse HTTP headers for cookies.
$cookies = [];

$contentType = $headers['Content-Type'] ?? null;
$contentType = $headers['content-type'] ?? $headers['Content-Type'] ?? null;
/*
* TODO Multipart form uploads are not supported yet.
*/
Expand Down
14 changes: 14 additions & 0 deletions tests/Bridge/Psr7/RequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ public function test POST body is parsed()
self::assertEquals(['foo' => 'bar', 'bim' => 'baz'], $request->getParsedBody());
}

public function test the content type header is not case sensitive()
{
$request = RequestFactory::fromLambdaEvent([
'httpMethod' => 'POST',
'headers' => [
// content-type instead of Content-Type
'content-type' => 'application/x-www-form-urlencoded',
],
'body' => 'foo=bar&bim=baz',
]);
self::assertEquals('POST', $request->getMethod());
self::assertEquals(['foo' => 'bar', 'bim' => 'baz'], $request->getParsedBody());
}

public function test POST JSON body is not parsed()
{
$request = RequestFactory::fromLambdaEvent([
Expand Down

0 comments on commit 6f1d955

Please sign in to comment.