Skip to content

Commit

Permalink
Let Slim parse HTTP_CONTENT_TYPE header for PHP built-in server
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Lockhart committed Feb 16, 2014
1 parent ff7d714 commit 32e8b03
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Slim/Http/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions tests/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 32e8b03

Please sign in to comment.