From 32e8b038c51945e984cfe4b7ce0caf0c908848bf Mon Sep 17 00:00:00 2001 From: Josh Lockhart Date: Sun, 16 Feb 2014 12:52:05 -0500 Subject: [PATCH] Let Slim parse HTTP_CONTENT_TYPE header for PHP built-in server --- Slim/Http/Headers.php | 2 +- tests/EnvironmentTest.php | 2 -- tests/Http/RequestTest.php | 13 +++++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Slim/Http/Headers.php b/Slim/Http/Headers.php index ac05df342..747cd12f9 100644 --- a/Slim/Http/Headers.php +++ b/Slim/Http/Headers.php @@ -72,7 +72,7 @@ public static function extract($data) foreach ($data as $key => $value) { $key = strtoupper($key); if (strpos($key, 'X_') === 0 || strpos($key, 'HTTP_') === 0 || in_array($key, static::$special)) { - if ($key === 'HTTP_CONTENT_TYPE' || $key === 'HTTP_CONTENT_LENGTH') { + if ($key === 'HTTP_CONTENT_LENGTH') { continue; } $results[$key] = $value; diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php index cb2b500ae..274701f54 100644 --- a/tests/EnvironmentTest.php +++ b/tests/EnvironmentTest.php @@ -277,10 +277,8 @@ public function testServerPortIsNotEmpty() */ public function testUnsetsContentTypeAndContentLength() { - $_SERVER['HTTP_CONTENT_TYPE'] = 'text/csv'; $_SERVER['HTTP_CONTENT_LENGTH'] = 150; $env = \Slim\Environment::getInstance(true); - $this->assertFalse(isset($env['HTTP_CONTENT_TYPE'])); $this->assertFalse(isset($env['HTTP_CONTENT_LENGTH'])); } diff --git a/tests/Http/RequestTest.php b/tests/Http/RequestTest.php index 9ffea7130..1f4a7d8d3 100644 --- a/tests/Http/RequestTest.php +++ b/tests/Http/RequestTest.php @@ -517,6 +517,19 @@ public function testGetContentTypeWhenNotExists() $this->assertNull($req->getContentType()); } + /** + * Test get content type with built-in server + */ + public function testGetContentTypeWithBuiltInServer() + { + $env = \Slim\Environment::mock(array( + 'slim.input' => '', + 'HTTP_CONTENT_TYPE' => 'application/json; charset=ISO-8859-4' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('application/json; charset=ISO-8859-4', $req->getContentType()); + } + /** * Test get media type */