Compare commits

..

No commits in common. "d0d0d4dc761309948b9f8e004a62861019ca670a" and "45abea53014cb4a380e87672109a1f0e68f0b185" have entirely different histories.

View File

@ -22,7 +22,6 @@ class Request extends Neuron {
public Neuron $params; public Neuron $params;
public string $path; public string $path;
public string $error; public string $error;
public string $body;
public array $next; public array $next;
/** /**
@ -38,18 +37,16 @@ class Request extends Neuron {
$this->put = new Neuron(); $this->put = new Neuron();
$this->patch = new Neuron(); $this->patch = new Neuron();
$this->delete = new Neuron(); $this->delete = new Neuron();
$this->body = file_get_contents("php://input");
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : ''; $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if ($contentType === "application/json") if ($contentType === "application/json")
$this->json = new Neuron( $this->json = new Neuron(
(object) json_decode(trim($this->body), false) (object) json_decode(trim(file_get_contents("php://input")), false)
); );
else { else {
$this->json = new Neuron(); $this->json = new Neuron();
if (in_array($_SERVER['REQUEST_METHOD'], ['PUT', 'PATCH', 'DELETE']) && if (in_array($_SERVER['REQUEST_METHOD'], ['PUT', 'PATCH', 'DELETE'])) {
preg_match('/^[^;?\/:@&=+$,]{1,255}[=]/', $this->body, $matches)) { // Con la expresión regular verificamos que sea un http query string válido y evitamos errores de memoria en caso de que el body tenga algo más grande que eso. parse_str(file_get_contents("php://input"), $input_vars);
parse_str($this->body, $input_vars);
$this->{strtolower($_SERVER['REQUEST_METHOD'])} = new Neuron($input_vars); $this->{strtolower($_SERVER['REQUEST_METHOD'])} = new Neuron($input_vars);
} }
} }