/** * Determines what error degredation method to perform * * @param array $error * * @return mixed */ public static function handleError($error) { if (is_array($error) === false) { return; } if (isset($error['odysseus']) === true && is_array($error['odysseus']) === true) { \OriginRequest::reportError($error); /** * Don't disclose any more server details */ $error = $error['error']; } switch (self::ERROR_REPORTING_LEVEL) { case self::ERROR_LEVEL_IGNORE: return; case self::ERROR_LEVEL_LOG: \error_log("An Odysseus client error has occurred: .\n" . var_export($error, true) . "\n"); return; case self::ERROR_LEVEL_DISPLAY: /** * Todo: come up with a better way of displaying these */ return; case self::ERROR_LEVEL_EXCEPTION: throw new \Exception('An Odysseus client error has occurred: ' . var_export($error, true)); case self::ERROR_LEVEL_DEBUG_API: echo "<pre>\n"; var_dump($error); echo "</pre>\n"; exit; } return; }
/** * Renders a 404 page for the given host for the current request * * @param bool $retry Retry is set when a new 404 page is retreived from Origin, and we need to perform a recursive call * in order to serve the new 404 page. * * @return void */ public static function render404($retry = false) { if (file_exists(\BASE_DOCROOT_DIR . '/404.html') === true) { self::sendHeader($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); self::render(file_get_contents(\BASE_DOCROOT_DIR . '/404.html')); } elseif ($retry === false) { /** * Might need to retrieve the 404 page from origin, but this should be rare */ $origin = OriginRequest::getObject(array('host' => \Configuration::DEPLOYED_HOSTNAME, array('path' => '/404.html', 'file' => '404.html'))); if ($origin === true) { self::render404(true); } } /** * Something's wrong, and we can't serve a 404 from origin, and we don't have a 404 page on disk. * Fail gracefully to minimal output. */ self::sendHeader($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); self::sendHeader('Cache-Control: no-cache'); self::render('Not Found'); }
/** * Receives an object to be placed at docroot * * @return void */ private function receiveObject() { \OriginRequest::expandObject($this->request['object']); return; }
/** * Constructor * On construct, Handler runs through everything needed to either render the requested page, or render a 404 * No methods are called outside of this class, and no values are returned * * @param array $request * * @return void */ public function __construct($request) { $this->buildSiteArray(); $this->buildRequestArray($request); /** * Is this an API request to a client API that we need to proxy along? */ if ($this->isClientApiRequest() === true) { \OriginAPI::makeClientAPIRequest($this->request, file_get_contents('php://input')); } if ($this->isPage() === true) { /** * Might have the mobile cookie, and just need to get redirected to mobile file on disk */ if ($this->request['mobile'] === true && file_exists(\BASE_DOCROOT_DIR . '/mobile/' . $this->request['file']) === true) { \setcookie('is_mobile', 1, time() + 2592000, '/'); \Output::sendHeader('Location: ' . $this->request['file']); $this->isRedirect = true; $this->finalizeOutput(); exit; } /** * Do we have it in the page hierarchy, or is it a dynamic page? Go get it from Origin */ if ($this->isPageInPublishedData($this->request['file']) === true || $this->isDynamicPage() === true) { $response = \OriginRequest::getObject($this->request); $this->handleOriginResponse($response); } else { \Output::render404(); } /** * Should we try a simple redirect from .htm to .html? */ if ($this->isPageInPublishedData($this->request['file'] . 'l') === true) { if (file_exists(\BASE_DOCROOT_DIR . '/' . $this->request['file']) === true) { \Output::sendHeader('Location: ' . $this->request['file'] . 'l'); $this->isRedirect = true; $this->finalizeOutput(); exit; } else { /** * Don't have it yet, go get it before forwarding */ $this->request['file'] .= 'l'; $response = \OriginRequest::getObject($this->request); $this->handleOriginResponse($response); } } } else { /** * Not a page, we have to use benefit of the doubt here for checking origin */ // Assets files. // Set default memory_limit so wServer will send back retryRaw message for file larger than 1MB. // Not setting it means it's remote server published before this change, // then wServer will always return old type of response. (no retryRaw mechanism) $this->request['memory_limit'] = MEMORY_LIMIT; $response = \OriginRequest::getObject($this->request); $this->handleOriginResponse($response); } // if redirect header, then add text to prevent some ftp server's firewall from block pure header redirect. $this->finalizeOutput(); }