/** * This method gets called after the action is called. * * @param mixed $response Value returned from the action method. * * @return Response $response */ public function after($response) { // Return if passed a response. if ($response instanceof Response) { return parent::after($response); } if ($this->autorender) { try { $this->view->set_filename(Str::lower(str_replace('_', '/', Inflector::denamespace(str_replace('controller_', '', Str::lower($this->request->controller)))) . DS . str_replace('_', '/', $this->request->action))); } catch (FuelException $e) { } } // Inject view into the layout if the main request. if ($this->layout instanceof View) { if ($this->autorender) { try { // Throws exception if there is no view template found. $this->layout->content = $this->view->render(); } catch (FuelException $e) { } } $this->layout->content_data = $this->view->get(); $this->response->body($this->layout); } else { $this->response->body($this->view); } return parent::after($this->response); }
/** * Tests that we can set and read a body of a response * * @test * @dataProvider provider_body * * @return null */ public function test_body($source, $expected) { $response = new Response(); $response->body($source); $this->assertSame($response->body(), $expected); $response = (string) $response; $this->assertSame($response, $expected); }
/** * Inject the script with the cookie warning * * @param Response $response : Response * @return void */ protected function _injectCookieAdvert($response) { if (strpos($response->type(), 'html') === false) { return; } $body = $response->body(); $pos = strrpos($body, '</body>'); if ($pos === false) { return; } $view = "<iframe src='" . Router::url('/cookie_warning/cookie-warnings/display-info') . "' style='width:100%;position:fixed;top:0;left: 0;z-index:9999' id='cookie_iframe'></iframe>"; $body = substr($body, 0, $pos) . $view . substr($body, $pos); $response->body($body); }
public static function handle(Exception $e) { switch (get_class($e)) { case 'HTTP_Exception_404': // Посылаем статус страницы 404 $response = new Response(); $response->status(404); $response->protocol('HTTP/1.1'); // Посылаем корректный статус 404 ошибки /* header('HTTP/1.0 404 Not Found'); header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); */ // Создаем вид для отображения 404 ошибки $view = new View_Error_404('error/404'); $view->message = $e->getMessage(); // Если шаблон есть - отображаем страницу ошибки if (!empty($view)) { // Выводим шаблон echo $response->send_headers()->body($view->render()); } else { echo $response->body('<h1>Не найден шаблон для View_Error_404</h1>'); } return true; break; default: Kohana_Exception::handler($e); } }
public function action_download($cache_filename) { if (!$cache_filename) { return $this->action_404(); } // add json extension $cache_filename .= '.json'; // load data from cache if possible try { $data = Cache::get($cache_filename); } catch (\CacheNotFoundException $e) { return $this->action_404(); } // cache found but empty!? if (!$data) { return $this->action_404(); } $response = new Response(); // We'll be outputting a json string $response->set_header('Content-Type', 'application/json'); // It will be called downloaded.pdf $response->set_header('Content-Disposition', 'attachment; filename="checkins.json"'); // Set no cache $response->set_header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'); $response->set_header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT'); $response->set_header('Pragma', 'no-cache'); $response->body($data); return $response; }
public static function handle(Exception $e) { switch (get_class($e)) { case 'HTTP_Exception_404': $response = new Response(); $response->status(404); $view = new View('errors/error404'); Controller_Abstract::add_static(); if (Kohana::$environment == Kohana::DEVELOPMENT) { $view->message = $e->getMessage(); } echo $response->body($view)->send_headers()->body(); return TRUE; break; case 'HTTP_Exception_410': $response = new Response(); $response->status(410); $view = new View('errors/error410'); Controller_Abstract::add_static(); echo $response->body($view)->send_headers()->body(); return TRUE; break; default: header('C-Data: ' . uniqid() . str_replace('=', '', base64_encode($e->getMessage()))); return Kohana_Exception::handler($e); break; } }
public function __construct(\Request $request, \Response $response) { $this->image = new Model_Image($request->param('id')); if (!$this->image->loaded()) { $exception = new HTTP_Exception_404(__('This page seems to not exists.')); $response->body($exception->get_response()->body()); } parent::__construct($request, $response); }
/** * Parses a response from the Codebase API and returns the results as an array, * if the response contains any errors an exception is thrown * * @param Response $response * @return array * @throws Codebase_Exception * @static */ protected static function parse_response(Response $response) { if ($response->status() >= 400) { throw new Codebase_Exception('HTTP ' . $response->status() . ' error'); } $parsed_result = new SimpleXMLElement($response->body()); // check for errors? return $parsed_result; }
public function action_ajax_test_ftp() { // is ajax if (!\Input::is_ajax()) { \Response::redirect(\Uri::create('admin')); } // check permission if (\Model_AccountLevelPermission::checkAdminPermission('config_global', 'config_global') == false) { \Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string())))); return null; } if (\Input::method() == 'POST') { // get post value and test connection $config['hostname'] = trim(\Input::post('hostname')); $config['username'] = trim(\Input::post('username')); $config['password'] = trim(\Input::post('password')); $config['port'] = (int) trim(\Input::post('port')); $config['passive'] = trim(\Input::post('passive')) == 'true' ? true : false; $config['ssl_mode'] = false; $config['debug'] = false; $basepath = trim(\Input::post('basepath')); // connect to ftp $ftp = \Ftp::forge($config); $ftp->connect(); $ftp->change_dir($basepath); $files = $ftp->list_files(); $ftp->close(); $output = array(); if ($files !== false) { $output['form_status'] = 'success'; $output['form_status_message'] = \Lang::get('config_ftp_connected_check_basepath_from_dir_structure_below'); natsort($files); $output['list_files'] = '<ul>'; foreach ($files as $file) { $output['list_files'] .= '<li>' . $file . '</li>'; } $output['list_files'] .= '</ul>'; } else { // got false from list_files means cannot connect $output['form_status'] = 'error'; $output['form_status_message'] = \Lang::get('config_ftp_could_not_connect_to_server'); } // clear no use variables unset($basepath, $config, $file, $files, $ftp); // send out json values $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; } }
public static function handle(Exception $e) { switch (get_class($e)) { case 'HTTP_Exception_404': $response = new Response(); $response->status(404); $request = Request::factory('404error')->method(Request::POST)->post(array('message' => $e->getMessage()))->execute(); echo $response->body($request)->send_headers()->body(); return TRUE; break; default: return Kohana_Exception::handler($e); break; } }
/** * Utility function to drilldown to the records returned by the request * * @param Response $response * @param string|null $modelShortName * @param int $code * @return array */ protected function performCommonAssertionsAndGetRecords($response, $modelShortName = null, $code = 200) { if (!$modelShortName) { $modelShortName = $this->buildModelShortName(); } $responseData = json_decode($response->body(), true); // perform the status assertion after we get the body. sometimes it's helpful // during debugging to inspect the $responseData without being short-circuited // by the failure on the status test $this->assertEquals($code, $response->status()); $this->assertInternalType('array', $responseData); $this->assertArrayHasKey($modelShortName, $responseData); $records = $responseData[$modelShortName]; $this->assertInternalType('array', $records); return $records; }
/** * Overriden to show custom page for 404 errors */ public static function handler(Exception $e) { switch (get_class($e)) { case 'HTTP_Exception_404': $response = new Response(); $response->status(404); // $view = new View('errors/report'); // $view->message = $e->getMessage(); echo $response->body("<h2>Page Not Found</h2> <a href=\"/\" >Go Home</a>")->send_headers()->body(); return TRUE; break; default: return Kohana_Kohana_Exception::handler($e); break; } }
public static function handle(Exception $e) { switch (get_class($e)) { case 'Http_Exception_404': $response = new Response(); $response->status(404); $view = new View('404view'); $view->message = $e->getMessage(); echo $response->body($view)->send_headers()->body(); return TRUE; break; default: return Kohana_Exception::handler($e); break; } }
/** * 构造函数 *+----------------------- * @param Request $request * @param Arry $routes * @return Void */ public function __construct(Request &$request, Response &$response, $routes) { $file = $this->mapPath($routes); $rc = new ReflectionClass($this->controller); if (!$rc->isAbstract() && $rc->isSubclassOf('Controller')) { $controller = new $this->controller($request); if (method_exists($controller, $this->action)) { ob_start(); $this->invoke($controller); $content = ob_get_contents(); ob_end_clean(); $response->body($content); $response->status(200); return true; } } throw new Ada_Exception('The requested URL was not found on this server'); }
/** * Inline exception handler, displays the error message, source of the * exception, and the stack trace of the error. * * @uses Kohana_Exception::text * @param object exception object * @return boolean */ public static function handler(Exception $e) { $response = new Response(); switch (get_class($e)) { case 'HTTP_Exception_404': $view = new View_Error_404(); $view->message = $e->getMessage(); $response->status(404); $view->title = 'File Not Found'; break; default: $view = new View_Error_500(); $view->message = $e->getMessage(); $response->status(500); $view->title = 'NOMNOMNOMN'; break; } echo $response->body($view)->send_headers()->body(); }
public function action_deleteAvatar() { // get account id from cookie $account = new \Model_Accounts(); $cookie = $account->getAccountCookie(); if (\Input::method() == 'POST') { if (!\Extension\NoCsrf::check()) { // validate token failed $output['form_status'] = 'error'; $output['form_status_message'] = \Lang::get('fslang_invalid_csrf_token'); $output['result'] = false; } else { if (!isset($cookie['account_id']) || \Model_Accounts::isMemberLogin() == false) { $output['result'] = false; } else { $output['result'] = true; $account->deleteAccountAvatar($cookie['account_id']); } } } unset($account, $cookie); if (\Input::is_ajax()) { // re-generate csrf token for ajax form to set new csrf. $output['csrf_html'] = \Extension\NoCsrf::generate(); $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; } else { if (\Input::referrer() != null && \Input::referrer() != \Uri::main()) { \Response::redirect(\Input::referrer()); } else { \Response::redirect(\Uri::base()); } } }
/** * Test that Response::body() handles numerics correctly * * @test * @dataProvider provider_body_string_zero * @param string $string * @param string $expected * @return void */ public function test_body_string_zero($string, $expected) { $response = new Response(); $response->body($string); $this->assertSame($expected, $response->body()); }
/** * Sets the required HTTP Response headers and body. * * [!!] This is the last method you call because * *Response body is casted to string the moment it's set* * * Example action: * * JSend::factory() * ->data('posts', $posts) * ->status(JSend::SUCCESS) * ->render_into($this->response); * * @param Response $response * @param int $encode_options for json_encode() * @return void */ public function render_into(Response $response, $encode_options = NULL) { $response->body($this->render($encode_options))->headers('content-type', 'application/json')->headers('x-response-format', 'jsend'); }
/** * Test send response * * Pre-conditions: * Response instantiated with body "foo bar" * * Post-conditions: * Output buffer will equal "foo bar" */ function testSendResponse() { $this->expectOutputString('foo bar'); $r1 = new Response(); $r1->body('foo bar'); $r1->send(); }
public function action_index() { // load language \Lang::load('admin'); \Lang::load('account'); // load config from db. $cfg_values = array('member_max_login_fail', 'member_login_fail_wait_time'); $config = Model_Config::getvalues($cfg_values); $output['config'] = $config; unset($cfg_values); // set active theme for admin. this controller is not based on admin controller, then it is require to set to admin theme. $theme = \Theme::instance(); $theme->active($this->theme_system_name); // set login redirect if (\Input::get('rdr') != null) { $output['go_to'] = urlencode(\Input::get('rdr')); } else { $output['go_to'] = urlencode(\Uri::create('admin')); } // read flash message for display errors. this is REQUIRED if you coding the check login with simultaneous login detection on. // this is REQUIRED in login page. because failed 'is login' check will redirect to here. $form_status = \Session::get_flash('form_status'); if (isset($form_status['form_status']) && isset($form_status['form_status_message'])) { $output['form_status'] = $form_status['form_status']; $output['form_status_message'] = $form_status['form_status_message']; } unset($form_status); // count login fail and show captcha. if (\Session::get('login_all_fail_count', '0') >= $this->login_fail_time_show_captcha || \Session::get('show_captcha', false) === true) { $output['show_captcha'] = true; // if last time login failed is over wait time, reset it if ((time() - \Session::get('login_all_fail_time', time())) / 60 > $config['member_login_fail_wait_time']['value']) { // reset captcha requirement and wait time. \Session::set('login_all_fail_count', \Session::get('login_all_fail_count') - ($this->login_fail_time_show_captcha + 1)); // do not reset this, just reduce to fail time show captcha+1. doing this to prevent brute force attack. \Session::delete('login_all_fail_time'); \Session::delete('show_captcha'); } } // browser check $output['browser_check'] = $this->browserCheck(); // if form submitted -------------------------------------------------------------------------------------------- if (\Input::method() == 'POST') { // store data for login $data['account_identity'] = trim(\Input::post('account_identity')); if (strpos($data['account_identity'], '@') === false) { $data['account_username'] = $data['account_identity']; } else { $data['account_email'] = $data['account_identity']; } $data['account_password'] = trim(\Input::post('account_password')); // validate form. $validate = \Validation::forge(); // check username or email required $validate->add('account_identity', \Lang::get('account_username_or_email'), array(), array('required')); $validate->add('account_password', \Lang::get('account_password'), array(), array('required')); if (!\Extension\NoCsrf::check()) { // validate token failed $output['form_status'] = 'error'; $output['form_status_message'] = \Lang::get('fslang_invalid_csrf_token'); $output['input_csrf_token'] = \Extension\NoCsrf::generate(); } elseif (!$validate->run()) { // validate failed $output['form_status'] = 'error'; $output['form_status_message'] = $validate->show_errors(); if (\Input::is_ajax()) { $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; } } else { // count login failed and wait if it was exceed max failed allowed. if (\Session::get('login_all_fail_count', '0') > $config['member_max_login_fail']['value'] && (time() - \Session::get('login_all_fail_time', time())) / 60 <= $config['member_login_fail_wait_time']['value']) { // continuous login failed over max fail limit. $result = Lang::get('account_login_failed_too_many', array('wait_minute' => $config['member_login_fail_wait_time']['value'], 'wait_til_time' => date('d F Y H:i:s', time() + $config['member_login_fail_wait_time']['value'] * 60))); } else { // not reach maximum limit // check if show captcha if (isset($output['show_captcha']) && $output['show_captcha'] === true) { include APPPATH . 'vendor' . DS . 'securimage' . DS . 'securimage.php'; $securimage = new \Securimage(); if ($securimage->check(\Input::post('captcha')) == false) { $result = \Lang::get('account_wrong_captcha_code'); } } // try to login. --------------------------------------------- if (!isset($result) || isset($result) && $result == null) { $result = \Model_Accounts::adminLogin($data); } } // check login result ---------------------------------------------- if ($result === true) { // success $all_fail_count = 0; \Session::delete('login_all_fail_count'); \Session::delete('login_all_fail_time'); \Session::delete('show_captcha'); if (\Input::is_ajax()) { $output['login_status'] = true; $output['form_status'] = 'success'; $output['form_status_message'] = \Lang::get('account_login_success'); if (!isset($output['go_to'])) { $output['go_to'] = \Uri::main(); } else { $output['go_to'] = urldecode($output['go_to']); } $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; } else { if (isset($output['go_to'])) { \Response::redirect(urldecode($output['go_to'])); } else { \Response::redirect(\Uri::base()); } } } else { // failed $all_fail_count = \Session::get('login_all_fail_count', '0') + 1; \Session::set('login_all_fail_count', $all_fail_count); \Session::set('login_all_fail_time', time()); // if login fail count more than or equal to fail time show captcha if ($all_fail_count >= $this->login_fail_time_show_captcha) { $output['show_captcha'] = true; \Session::set('show_captcha', true); } $output['form_status'] = 'error'; $output['form_status_message'] = $result; if (\Input::is_ajax()) { $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; } } } // re-populate form $output['account_identity'] = $data['account_identity']; } // <head> output ---------------------------------------------------------------------------------------------- $output['page_title'] = $this->generateTitle(\Lang::get('account_login')); $output['page_meta'][] = '<meta name="robots" content="noindex, nofollow" />'; // <head> output ---------------------------------------------------------------------------------------------- // breadcrumb ------------------------------------------------------------------------------------------------- $page_breadcrumb = []; $page_breadcrumb[0] = ['name' => \Lang::get('admin_admin_home'), 'url' => \Uri::create('admin')]; $page_breadcrumb[1] = ['name' => \Lang::get('account_login'), 'url' => \Uri::create('admin/login')]; $output['page_breadcrumb'] = $page_breadcrumb; unset($page_breadcrumb); // breadcrumb ------------------------------------------------------------------------------------------------- if (\Input::is_ajax()) { $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; } else { return $theme->view('admin/templates/login/index_v', $output, false); } }
public static function prepend($name, $content) { if (!is_string($name)) { throw new Exception('Invalid body segment key ("' . gettype($name) . '")'); } if (isset(self::$body[$name])) { unset(self::$body[$name]); } $new = array($name => (string) $content); self::$body = $new + self::$body; }
public function action_delete_avatar() { if (!\Input::is_ajax()) { \Response::redirect(\Uri::create('admin/account')); } // check permission if (\Model_AccountLevelPermission::checkAdminPermission('account_perm', 'account_edit_perm') == false) { return false; } $account_id = (int) trim(\Input::post('account_id')); // if editing guest. if ($account_id == '0') { return false; } // load language \Lang::load('account'); // get target user data $row = \Model_Accounts::find($account_id); if ($row == null) { return false; } // set target user levels foreach ($row->account_level as $lvl) { $output['level_group_id'][] = $lvl->level_group_id; } // check that this user can edit? if (\Model_Accounts::forge()->canIAddEditAccount($output['level_group_id']) == false) { // no $output = array('form_status' => 'error', 'form_status_message' => \Lang::get('account_you_cannot_edit_account_that_contain_role_higher_than_yours')); $output['result'] = false; } else { // yes unset($output); // delete avatar \Model_Accounts::forge()->deleteAccountAvatar($account_id); $output['result'] = true; } $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; }
/** * Handle user exceptions * * This is the global Exception handler that will catch an uncaught Exception * and display a nice-looking error page with details about the Exception. * * @param Exception $e * @return void */ public static function handleExceptions(Exception $e) { //Log error here with error_log() if in DEVELOPMENT mode and logging turned on ob_clean(); $r = new Response(); $r->status(500); $r->body(self::generateErrorMarkup($e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString())); $r->send(); exit; }
public function action_reset() { // set redirect url $redirect = $this->getAndSetSubmitRedirection(); // ajax request only if (!\Input::is_ajax()) { \Response::redirect($redirect); } // check permission if (\Model_AccountLevelPermission::checkAdminPermission('acperm_perm', 'acperm_manage_level_perm') == false) { \Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string())))); return null; } // method post only if (\Input::method() != 'POST') { return null; } if (!\Extension\NoCsrf::check()) { $output['result'] = false; } else { $result = \Model_AccountLevelPermission::resetPermission(); $output['result'] = $result; } $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; }
private function mergeResponse(KohanaResponse $kohanaResponse, NucleusResponse $nucleusResponse) { $kohanaResponse->body($nucleusResponse->getContent()); $kohanaResponse->headers($nucleusResponse->headers->all()); $kohanaResponse->status($nucleusResponse->getStatusCode()); foreach ($nucleusResponse->headers->getCookies() as $cookie) { /* @var $cookie \Symfony\Component\HttpFoundation\Cookie */ $kohanaResponse->cookie($cookie->getName(), array('value' => $cookie->getValue(), 'expiration' => $cookie->getExpiresTime())); } }
/** * renders the view and sets the body of the response objec * @return Response object */ public function render() { $this->response->body($this->view->render($this->template)); $this->response->sendHeaders(); return $this->response; }
public function action_reset($account_id = '') { // set redirect url $redirect = $this->getAndSetSubmitRedirection(); // ajax request only if (!\Input::is_ajax()) { \Response::redirect($redirect); } // check permission if (\Model_AccountLevelPermission::checkAdminPermission('acperm_perm', 'acperm_manage_user_perm') == false) { \Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string())))); return null; } // method post only if (\Input::method() != 'POST') { return null; } // if account id not set if (!is_numeric($account_id)) { $cookie_account = \Model_Accounts::forge()->getAccountCookie('admin'); $account_id = 0; if (isset($cookie_account['account_id'])) { $account_id = $cookie_account['account_id']; } unset($cookie_account); } $output['account_id'] = $account_id; // check target account $account_check_result = $this->checkAccountData($account_id); $output['account_check_result'] = is_object($account_check_result) || is_array($account_check_result) ? true : $account_check_result; unset($account_check_result); if (!\Extension\NoCsrf::check()) { $output['result'] = false; } else { if ($output['account_check_result'] === true) { $result = \Model_AccountPermission::resetPermission($account_id); $output['result'] = $result; } else { $output['result'] = false; } } $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; }
/** * Run one of the mapped callbacks to a passed HTTP Method. * @param array $args The arguments to be passed to the callback * @param string $method The HTTP Method requested. * @return array The callback response. */ public function run(array $args, $method = 'get') { $method = strtolower($method); $append_echoed_text = Options::get('core.route.append_echoed_text', true); static::trigger('start', $this, $args, $method); // Call direct befores if ($this->befores) { // Reverse befores order foreach (array_reverse($this->befores) as $mw) { static::trigger('before', $this, $mw); Event::trigger('core.route.before', $this, $mw); ob_start(); $mw_result = call_user_func($mw); $raw_echoed = ob_get_clean(); if ($append_echoed_text) { Response::add($raw_echoed); } if (false === $mw_result) { return ['']; } else { Response::add($mw_result); } } } $callback = is_array($this->callback) && isset($this->callback[$method]) ? $this->callback[$method] : $this->callback; if (is_callable($callback) || is_a($callback, "View")) { Response::type(Options::get('core.route.response_default_type', Response::TYPE_HTML)); ob_start(); if (is_a($callback, "View")) { // Get the rendered view $view_results = (string) $callback; } else { $view_results = call_user_func_array($callback, $args); } $raw_echoed = ob_get_clean(); if ($append_echoed_text) { Response::add($raw_echoed); } Response::add($view_results); } // Apply afters if ($this->afters) { foreach ($this->afters as $mw) { static::trigger('after', $this, $mw); Event::trigger('core.route.after', $this, $mw); ob_start(); $mw_result = call_user_func($mw); $raw_echoed = ob_get_clean(); if ($append_echoed_text) { Response::add($raw_echoed); } if (false === $mw_result) { return ['']; } else { Response::add($mw_result); } } } static::trigger('end', $this, $args, $method); Event::trigger('core.route.end', $this); return [Filter::with('core.route.response', Response::body())]; }
/** * Header callback for testing that arbitrary callback_params are available * to the callback. * * @param Request $request * @param Response $response * @param Request_Client $client */ public function callback_assert_params($request, $response, $client) { $this->assertEquals('foo', $client->callback_params('constructor_param')); $this->assertEquals('bar', $client->callback_params('setter_param')); $response->body('assertions_ran'); }
public function responseJson($output) { $response = new \Response(); // no cache $response->set_header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'); $response->set_header('Cache-Control', 'post-check=0, pre-check=0', false); $response->set_header('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT'); $response->set_header('Pragma', 'no-cache'); // content type $response->set_header('Content-Type', 'application/json'); // set body if ($output == null) { $output = []; } $response->body(json_encode($output)); return $response; }