Fix fix of POST :P
This commit is contained in:
parent
8a018d7a59
commit
aedc427ffd
|
@ -31,6 +31,7 @@ use OCP\IRequest;
|
||||||
|
|
||||||
class Request implements \ArrayAccess, \Countable, IRequest {
|
class Request implements \ArrayAccess, \Countable, IRequest {
|
||||||
|
|
||||||
|
protected $inputStream;
|
||||||
protected $content;
|
protected $content;
|
||||||
protected $items = array();
|
protected $items = array();
|
||||||
protected $allowedKeys = array(
|
protected $allowedKeys = array(
|
||||||
|
@ -66,12 +67,19 @@ class Request implements \ArrayAccess, \Countable, IRequest {
|
||||||
: array();
|
: array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
|
||||||
|
&& in_array('fakeinput', stream_get_wrappers())) {
|
||||||
|
$this->inputStream = 'fakeinput://data';
|
||||||
|
} else {
|
||||||
|
$this->inputStream = 'php://input';
|
||||||
|
}
|
||||||
|
|
||||||
// Only 'application/x-www-form-urlencoded' requests are automatically
|
// Only 'application/x-www-form-urlencoded' requests are automatically
|
||||||
// transformed by PHP, 'application/json' must be decoded manually.
|
// transformed by PHP, 'application/json' must be decoded manually.
|
||||||
if ($this->method === 'POST'
|
if ($this->method === 'POST'
|
||||||
&& strpos($this->getHeader('Content-Type'), 'application/json') !== false
|
&& strpos($this->getHeader('Content-Type'), 'application/json') !== false
|
||||||
) {
|
) {
|
||||||
$this->items['params'] = $this->items['post'] = json_decode(file_get_contents('php://input'), true);
|
$this->items['params'] = $this->items['post'] = json_decode(file_get_contents($this->inputStream), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->items['parameters'] = array_merge(
|
$this->items['parameters'] = array_merge(
|
||||||
|
@ -311,24 +319,17 @@ class Request implements \ArrayAccess, \Countable, IRequest {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
|
|
||||||
&& in_array('fakeinput', stream_get_wrappers())) {
|
|
||||||
$stream = 'fakeinput://data';
|
|
||||||
} else {
|
|
||||||
$stream = 'php://input';
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the content can't be parsed into an array then return a stream resource.
|
// If the content can't be parsed into an array then return a stream resource.
|
||||||
if ($this->method === 'PUT'
|
if ($this->method === 'PUT'
|
||||||
&& strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false
|
&& strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false
|
||||||
&& strpos($this->getHeader('Content-Type'), 'application/json') === false
|
&& strpos($this->getHeader('Content-Type'), 'application/json') === false
|
||||||
) {
|
) {
|
||||||
$this->content = false;
|
$this->content = false;
|
||||||
return fopen($stream, 'rb');
|
return fopen($this->inputStream, 'rb');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->content)) {
|
if (is_null($this->content)) {
|
||||||
$this->content = file_get_contents($stream);
|
$this->content = file_get_contents($this->inputStream);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Normal jquery ajax requests are sent as application/x-www-form-urlencoded
|
* Normal jquery ajax requests are sent as application/x-www-form-urlencoded
|
||||||
|
|
|
@ -115,8 +115,9 @@ class RequestTest extends \PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testJsonPost() {
|
public function testJsonPost() {
|
||||||
|
global $data;
|
||||||
|
$data = '{"name": "John Q. Public", "nickname": "Joey"}';
|
||||||
$vars = array(
|
$vars = array(
|
||||||
'post' => '{"name": "John Q. Public", "nickname": "Joey"}',
|
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'server' => array('CONTENT_TYPE' => 'application/json; utf-8'),
|
'server' => array('CONTENT_TYPE' => 'application/json; utf-8'),
|
||||||
);
|
);
|
||||||
|
@ -135,7 +136,6 @@ class RequestTest extends \PHPUnit_Framework_TestCase {
|
||||||
$data = http_build_query(array('name' => 'John Q. Public', 'nickname' => 'Joey'), '', '&');
|
$data = http_build_query(array('name' => 'John Q. Public', 'nickname' => 'Joey'), '', '&');
|
||||||
|
|
||||||
$vars = array(
|
$vars = array(
|
||||||
'patch' => $data,
|
|
||||||
'method' => 'PATCH',
|
'method' => 'PATCH',
|
||||||
'server' => array('CONTENT_TYPE' => 'application/x-www-form-urlencoded'),
|
'server' => array('CONTENT_TYPE' => 'application/x-www-form-urlencoded'),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue