mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 16:44:39 +00:00
MVC: Routing - remove setJsonContent and make sure Response->send() handles array types properly. closes https://github.com/opnsense/core/issues/7757
Since we already handle stream output in send() as well, it makes sense to push the render decision to that spot in full.
This commit is contained in:
parent
3e99b87cdf
commit
f3669a58d7
@ -268,7 +268,7 @@ class ApiControllerBase extends ControllerRoot
|
||||
// not authenticated
|
||||
$this->response->setStatusCode(403, "Forbidden");
|
||||
$this->response->setContentType('application/json', 'UTF-8');
|
||||
$this->response->setJsonContent(['status' => 403,'message' => 'Forbidden']);
|
||||
$this->response->setContent(['status' => 403,'message' => 'Forbidden']);
|
||||
$this->response->send();
|
||||
return false;
|
||||
} else {
|
||||
@ -279,7 +279,7 @@ class ApiControllerBase extends ControllerRoot
|
||||
if ($dispatchError != null) {
|
||||
$this->response->setStatusCode(400, "Bad Request");
|
||||
$this->response->setContentType('application/json', 'UTF-8');
|
||||
$this->response->setJsonContent(['status' => 400, 'message' => $dispatchError]);
|
||||
$this->response->setContent(['status' => 400, 'message' => $dispatchError]);
|
||||
$this->response->send();
|
||||
return false;
|
||||
}
|
||||
@ -301,7 +301,7 @@ class ApiControllerBase extends ControllerRoot
|
||||
// not authenticated
|
||||
$this->response->setStatusCode(401, "Unauthorized");
|
||||
$this->response->setContentType('application/json', 'UTF-8');
|
||||
$this->response->setJsonContent(['status' => 401, 'message' => 'Authentication Failed']);
|
||||
$this->response->setContent(['status' => 401, 'message' => 'Authentication Failed']);
|
||||
$this->response->send();
|
||||
return false;
|
||||
} else {
|
||||
|
||||
@ -107,7 +107,11 @@ class Response
|
||||
fpassthru($this->content);
|
||||
@fclose($this->content);
|
||||
} elseif (!empty($this->content)) {
|
||||
echo $this->content;
|
||||
if (is_array($this->content)) {
|
||||
echo json_encode($this->content);
|
||||
} else {
|
||||
echo $this->content;
|
||||
}
|
||||
}
|
||||
|
||||
$this->sent = true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user