From 6f1d95563f46f84b796fb2c5dfe5b6e203fc3c6d Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 14 May 2018 09:55:27 +0200 Subject: [PATCH] Fix POST bug with case-insensitive header detection --- src/Bridge/Psr7/RequestFactory.php | 2 +- tests/Bridge/Psr7/RequestFactoryTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Bridge/Psr7/RequestFactory.php b/src/Bridge/Psr7/RequestFactory.php index 976a60801..24a259eac 100644 --- a/src/Bridge/Psr7/RequestFactory.php +++ b/src/Bridge/Psr7/RequestFactory.php @@ -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. */ diff --git a/tests/Bridge/Psr7/RequestFactoryTest.php b/tests/Bridge/Psr7/RequestFactoryTest.php index fcb2747c6..6031b83f6 100644 --- a/tests/Bridge/Psr7/RequestFactoryTest.php +++ b/tests/Bridge/Psr7/RequestFactoryTest.php @@ -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([