Skip to content

Commit 6f1d955

Browse files
committed
Fix POST bug with case-insensitive header detection
1 parent 38b1b2d commit 6f1d955

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Bridge/Psr7/RequestFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function fromLambdaEvent(array $event) : ServerRequestInterface
3232
// TODO Parse HTTP headers for cookies.
3333
$cookies = [];
3434

35-
$contentType = $headers['Content-Type'] ?? null;
35+
$contentType = $headers['content-type'] ?? $headers['Content-Type'] ?? null;
3636
/*
3737
* TODO Multipart form uploads are not supported yet.
3838
*/

tests/Bridge/Psr7/RequestFactoryTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ public function test POST body is parsed()
6969
self::assertEquals(['foo' => 'bar', 'bim' => 'baz'], $request->getParsedBody());
7070
}
7171

72+
public function test the content type header is not case sensitive()
73+
{
74+
$request = RequestFactory::fromLambdaEvent([
75+
'httpMethod' => 'POST',
76+
'headers' => [
77+
// content-type instead of Content-Type
78+
'content-type' => 'application/x-www-form-urlencoded',
79+
],
80+
'body' => 'foo=bar&bim=baz',
81+
]);
82+
self::assertEquals('POST', $request->getMethod());
83+
self::assertEquals(['foo' => 'bar', 'bim' => 'baz'], $request->getParsedBody());
84+
}
85+
7286
public function test POST JSON body is not parsed()
7387
{
7488
$request = RequestFactory::fromLambdaEvent([

0 commit comments

Comments
 (0)