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:
commit
189b519135
|
@ -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]));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue