fix: Only get params from PUT content if possible

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2023-02-03 14:47:19 +01:00 committed by backportbot-nextcloud[bot]
parent 528a79c34e
commit 119babd9a2

View file

@ -268,6 +268,9 @@ class Request implements \ArrayAccess, \Countable, IRequest {
: null;
case 'parameters':
case 'params':
if ($this->isPutStreamContent()) {
return $this->items['parameters'];
}
return $this->getContent();
default:
return isset($this[$name])
@ -399,12 +402,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
*/
protected function getContent() {
// If the content can't be parsed into an array then return a stream resource.
if ($this->method === 'PUT'
&& $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
) {
if ($this->isPutStreamContent()) {
if ($this->content === false) {
throw new \LogicException(
'"put" can only be accessed once if not '
@ -419,6 +417,14 @@ class Request implements \ArrayAccess, \Countable, IRequest {
}
}
private function isPutStreamContent(): bool {
return $this->method === 'PUT'
&& $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;
}
/**
* Attempt to decode the content and populate parameters
*/