Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function __get($name) {
if ($this->method !== strtoupper($name)) {
throw new \LogicException(sprintf('%s cannot be accessed in a %s request.', $name, $this->method));
}
return $this->getContent();
return $this->getContent(false);
case 'files':
case 'server':
case 'env':
Expand All @@ -268,7 +268,7 @@ public function __get($name) {
: null;
case 'parameters':
case 'params':
return $this->getContent();
return $this->getContent(true);
default:
return isset($this[$name])
? $this[$name]
Expand Down Expand Up @@ -389,25 +389,28 @@ public function getCookie(string $key) {
/**
* Returns the request body content.
*
* If the HTTP request method is PUT and the body
* not application/x-www-form-urlencoded or application/json a stream
* resource is returned, otherwise an array.
* If the HTTP request method is PUT or POST and the body
* not application/x-www-form-urlencoded or application/json
* and $onlyParameters is false
* a stream resource is returned, otherwise an array.
*
* @param bool $onlyParameters true if only parsed parameters array needed
* @return array|string|resource The request body content or a resource to read the body stream.
*
* @throws \LogicException
*/
protected function getContent() {
protected function getContent(bool $onlyParameters) {
// If the content can't be parsed into an array then return a stream resource.
if ($this->method === 'PUT'
if (($this->method === 'PUT' || $this->method === 'POST')
&& $this->getHeader('Content-Length') !== '0'
&& $this->getHeader('Content-Length') !== ''
&& strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false
&& strpos($this->getHeader('Content-Type'), 'application/json') === false
&& !$onlyParameters
) {
if ($this->content === false) {
throw new \LogicException(
'"put" can only be accessed once if not '
'"' . strtolower($this->method) . '" can only be accessed once if not '
. 'application/x-www-form-urlencoded or application/json.'
);
}
Expand Down