Merge pull request #3486 from Icinga/fix/request-parses-json-without-respecting-content-type-3484

Fix that Request parses json without respecting content type
This commit is contained in:
Eric Lippmann 2018-07-05 13:19:27 +02:00 committed by GitHub
commit 189b519135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 3 deletions

View File

@ -124,8 +124,24 @@ class Request extends Zend_Controller_Request_Http
public function getPost($key = null, $default = null)
{
return $key === null && $this->isApiRequest()
? Json::decode(file_get_contents('php://input'), true)
: parent::getPost($key, $default);
if ($key === null && $this->extractMediaType($this->getHeader('Content-Type')) === 'application/json') {
return Json::decode(file_get_contents('php://input'), true);
}
return parent::getPost($key, $default);
}
/**
* Extract and return the media type from the given header value
*
* @param string $headerValue
*
* @return string
*/
protected function extractMediaType($headerValue)
{
// Pretty basic and does not care about parameters
$parts = explode(';', $headerValue, 2);
return strtolower(trim($parts[0]));
}
}