Skip to content

Commit

Permalink
Fix getContent so body content stream can be accessed on POST method
Browse files Browse the repository at this point in the history
  • Loading branch information
xklonx committed Nov 1, 2019
1 parent d29d116 commit a8d3aac
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,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 @@ -277,7 +277,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 @@ -400,20 +400,23 @@ public function getCookie(string $key) {
* Returns the request body content.
*
* If the HTTP request method is PUT or POST and the body
* not application/x-www-form-urlencoded or application/json a stream
* resource is returned, otherwise an array.
* 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' || $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(
Expand Down

0 comments on commit a8d3aac

Please sign in to comment.