From 6c37f918b126a8516b41c7a702c08e80b766df99 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 30 Jan 2011 08:44:28 -0800 Subject: [PATCH] Somewhat proper 404 page, plus HTTP response code. --- .../AphrontDefaultApplicationConfiguration.php | 11 ++++++++++- src/aphront/default/configuration/__init__.php | 1 + src/aphront/response/base/AphrontResponse.php | 10 ++++++++++ src/applications/base/controller/404/__init__.php | 13 +++++++++++++ webroot/index.php | 6 ++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/applications/base/controller/404/__init__.php diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index c81c7a6c7a..d040b13277 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -150,13 +150,22 @@ class AphrontDefaultApplicationConfiguration $response->setContent($view->render()); return $response; } + } else if ($response instanceof Aphront404Response) { + $view = new PhabricatorStandardPageView(); + $view->appendChild('404 Not Found'); + $view->setTitle('404 Not Found'); + + $response = new AphrontWebpageResponse(); + $response->setContent($view->render()); + $response->setHTTPResponseCode(404); + return $response; } return $response; } public function build404Controller() { - return new Phabricator404Controller($request); + return array(new Phabricator404Controller($this->getRequest()), array()); } diff --git a/src/aphront/default/configuration/__init__.php b/src/aphront/default/configuration/__init__.php index f841860f69..66935aa326 100644 --- a/src/aphront/default/configuration/__init__.php +++ b/src/aphront/default/configuration/__init__.php @@ -9,6 +9,7 @@ phutil_require_module('phabricator', 'aphront/applicationconfiguration'); phutil_require_module('phabricator', 'aphront/request'); phutil_require_module('phabricator', 'aphront/response/webpage'); +phutil_require_module('phabricator', 'applications/base/controller/404'); phutil_require_module('phabricator', 'view/page/standard'); phutil_require_module('phutil', 'markup'); diff --git a/src/aphront/response/base/AphrontResponse.php b/src/aphront/response/base/AphrontResponse.php index 29a371c08d..c8ea750562 100644 --- a/src/aphront/response/base/AphrontResponse.php +++ b/src/aphront/response/base/AphrontResponse.php @@ -23,6 +23,7 @@ abstract class AphrontResponse { private $request; private $cacheable = false; + private $responseCode = 200; public function setRequest($request) { $this->request = $request; @@ -41,6 +42,15 @@ abstract class AphrontResponse { $this->cacheable = $duration; return $this; } + + public function setHTTPResponseCode($code) { + $this->responseCode = $code; + return $this; + } + + public function getHTTPResponseCode() { + return $this->responseCode; + } public function getCacheHeaders() { if ($this->cacheable) { diff --git a/src/applications/base/controller/404/__init__.php b/src/applications/base/controller/404/__init__.php new file mode 100644 index 0000000000..e3accbe46e --- /dev/null +++ b/src/applications/base/controller/404/__init__.php @@ -0,0 +1,13 @@ +willSendResponse($response); $response->setRequest($request); $response_string = $response->buildResponseString(); + +$code = $response->getHTTPResponseCode(); +if ($code != 200) { + header("HTTP/1.0 {$code}"); +} + $headers = $response->getCacheHeaders(); $headers = array_merge($headers, $response->getHeaders()); foreach ($headers as $header) {