diff --git a/src/aphront/sink/AphrontHTTPSink.php b/src/aphront/sink/AphrontHTTPSink.php index 88773cdff0..875aafa3f0 100644 --- a/src/aphront/sink/AphrontHTTPSink.php +++ b/src/aphront/sink/AphrontHTTPSink.php @@ -96,13 +96,16 @@ abstract class AphrontHTTPSink { * @return void */ final public function writeResponse(AphrontResponse $response) { + // Do this first, in case it throws. + $response_string = $response->buildResponseString(); + $all_headers = array_merge( $response->getHeaders(), $response->getCacheHeaders()); $this->writeHTTPStatus($response->getHTTPResponseCode()); $this->writeHeaders($all_headers); - $this->writeData($response->buildResponseString()); + $this->writeData($response_string); } diff --git a/webroot/index.php b/webroot/index.php index 1f56a1d0bd..53069daeac 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -26,6 +26,8 @@ try { PhutilErrorHandler::setErrorListener( array('DarkConsoleErrorLogPluginAPI', 'handleErrors')); + $sink = new AphrontPHPHTTPSink(); + if (PhabricatorEnv::getEnvConfig('phabricator.setup')) { try { PhabricatorSetup::runSetup(); @@ -48,7 +50,6 @@ try { break; } - $application->setHost($host); $application->setPath($path); $application->willBuildRequest(); @@ -100,7 +101,9 @@ try { $response = $controller->didProcessRequest($response); $response = $application->willSendResponse($response, $controller); $response->setRequest($request); - $response_string = $response->buildResponseString(); + + $sink->writeResponse($response); + } catch (Exception $ex) { $write_guard->dispose(); if ($access_log) { @@ -119,18 +122,6 @@ try { $write_guard->dispose(); - // TODO: Share the $sink->writeResponse() pathway here? - - $sink = new AphrontPHPHTTPSink(); - $sink->writeHTTPStatus($response->getHTTPResponseCode()); - - $headers = $response->getCacheHeaders(); - $headers = array_merge($headers, $response->getHeaders()); - - $sink->writeHeaders($headers); - - $sink->writeData($response_string); - if ($access_log) { $request_start = PhabricatorStartup::getStartTime(); $access_log->setData(