/** * Returns a response to the client. * @param {boolean} [$closeConnection=false] Whether to send headers to close the connection * @method response * @static */ static function response($closeConnection = false) { if (self::$servedResponse) { return; // response was served, and no new dispatch started } // Start buffering the response, unless otherwise requested $handler = Q_Response::isBuffered(); if ($handler !== false) { $ob = new Q_OutputBuffer($handler); } if (!empty($_GET['Q_ct'])) { Q_Response::setCookie('Q_ct', $_GET['Q_ct']); } if (!empty($_GET['Q_cordova'])) { Q_Response::setCookie('Q_cordova', $_GET['Q_cordova']); } Q_Response::sendCookieHeaders(); // Generate and render a response /** * Gives the app a chance to generate a response. * You should not change the server state when handling this event. * @event Q/response * @param {array} $routed */ self::$startedResponse = true; Q::event("Q/response", self::$routed); if ($closeConnection) { header("Connection: close"); header("Content-Length: " . $ob->getLength()); } if (!empty($ob)) { $ob->endFlush(); } if ($closeConnection) { ob_end_flush(); flush(); } self::$servedResponse = true; self::result("Served response"); return true; }