diff --git a/src/RequestParser.php b/src/RequestParser.php index c213ec23..c691dfec 100644 --- a/src/RequestParser.php +++ b/src/RequestParser.php @@ -133,7 +133,7 @@ public function parseBody($content) return; } - if (strtolower($headers['Content-Type']) == 'application/x-www-form-urlencoded') { + elseif (strpos(strtolower($headers['Content-Type']), 'application/x-www-form-urlencoded') === 0) { parse_str(urldecode($content), $result); $this->request->setPost($result); diff --git a/tests/RequestParserTest.php b/tests/RequestParserTest.php index 728166b3..b5f140b1 100644 --- a/tests/RequestParserTest.php +++ b/tests/RequestParserTest.php @@ -143,7 +143,10 @@ public function testShouldReceiveMultiPartBody() $this->assertEquals(2, count($request->getFiles()['files'])); } - public function testShouldReceivePostInBody() + /** + * @dataProvider shouldReceivePostInBodyDataProvider + */ + public function testShouldReceivePostInBody($postData) { $request = null; $body = null; @@ -154,7 +157,7 @@ public function testShouldReceivePostInBody() $body = $parsedBodyBuffer; }); - $parser->feed($this->createPostWithContent()); + $parser->feed($postData); $this->assertInstanceOf('React\Http\Request', $request); $this->assertSame('', $body); @@ -164,6 +167,14 @@ public function testShouldReceivePostInBody() ); } + public function shouldReceivePostInBodyDataProvider() + { + return [ + [$this->createPostWithContent()], + [$this->createPostWithContentUtf8Charset()] + ]; + } + public function testHeaderOverflowShouldEmitError() { $error = null; @@ -260,6 +271,20 @@ private function createPostWithContent() return $data; } + private function createPostWithContentUtf8Charset() + { + $data = "POST /foo?bar=baz HTTP/1.1\r\n"; + $data .= "Host: localhost:8080\r\n"; + $data .= "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:32.0) Gecko/20100101 Firefox/32.0\r\n"; + $data .= "Connection: close\r\n"; + $data .= "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n"; + $data .= "Content-Length: 79\r\n"; + $data .= "\r\n"; + $data .= "user=single&user2=second&users%5B%5D=first+in+array&users%5B%5D=second+in+array\r\n"; + + return $data; + } + private function createMultipartRequest() { $data = "POST / HTTP/1.1\r\n";