Compare commits
2 Commits
45abea5301
...
d0d0d4dc76
Author | SHA1 | Date | |
---|---|---|---|
d0d0d4dc76 | |||
595e9c1316 |
@ -22,6 +22,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,16 +38,18 @@ 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(file_get_contents("php://input")), false)
|
(object) json_decode(trim($this->body), 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']) &&
|
||||||
parse_str(file_get_contents("php://input"), $input_vars);
|
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($this->body, $input_vars);
|
||||||
$this->{strtolower($_SERVER['REQUEST_METHOD'])} = new Neuron($input_vars);
|
$this->{strtolower($_SERVER['REQUEST_METHOD'])} = new Neuron($input_vars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user