mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 10:12:41 +01:00
Share more HTTPSink code
Summary: In the past, we did some additional magic on `$response_string` (adding profiling headers? Or DarkConsole?), so we could not share the pathway with HTTPSink. We no longer do this; share the pathways. Also remove error handler initialization (duplicated in PhabricatorEnv), and move $sink initialization earlier. My general goal here is to allow PhabricatorSetup to emit a normal Response object and share as much code as possible with normal pages. Test Plan: Loaded page. Reviewers: btrahan, vrana Reviewed By: btrahan CC: aran Maniphest Tasks: T2228 Differential Revision: https://secure.phabricator.com/D4285
This commit is contained in:
parent
9e6d59829c
commit
3eb370a533
2 changed files with 9 additions and 15 deletions
|
@ -96,13 +96,16 @@ abstract class AphrontHTTPSink {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
final public function writeResponse(AphrontResponse $response) {
|
final public function writeResponse(AphrontResponse $response) {
|
||||||
|
// Do this first, in case it throws.
|
||||||
|
$response_string = $response->buildResponseString();
|
||||||
|
|
||||||
$all_headers = array_merge(
|
$all_headers = array_merge(
|
||||||
$response->getHeaders(),
|
$response->getHeaders(),
|
||||||
$response->getCacheHeaders());
|
$response->getCacheHeaders());
|
||||||
|
|
||||||
$this->writeHTTPStatus($response->getHTTPResponseCode());
|
$this->writeHTTPStatus($response->getHTTPResponseCode());
|
||||||
$this->writeHeaders($all_headers);
|
$this->writeHeaders($all_headers);
|
||||||
$this->writeData($response->buildResponseString());
|
$this->writeData($response_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ try {
|
||||||
PhutilErrorHandler::setErrorListener(
|
PhutilErrorHandler::setErrorListener(
|
||||||
array('DarkConsoleErrorLogPluginAPI', 'handleErrors'));
|
array('DarkConsoleErrorLogPluginAPI', 'handleErrors'));
|
||||||
|
|
||||||
|
$sink = new AphrontPHPHTTPSink();
|
||||||
|
|
||||||
if (PhabricatorEnv::getEnvConfig('phabricator.setup')) {
|
if (PhabricatorEnv::getEnvConfig('phabricator.setup')) {
|
||||||
try {
|
try {
|
||||||
PhabricatorSetup::runSetup();
|
PhabricatorSetup::runSetup();
|
||||||
|
@ -48,7 +50,6 @@ try {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$application->setHost($host);
|
$application->setHost($host);
|
||||||
$application->setPath($path);
|
$application->setPath($path);
|
||||||
$application->willBuildRequest();
|
$application->willBuildRequest();
|
||||||
|
@ -100,7 +101,9 @@ try {
|
||||||
$response = $controller->didProcessRequest($response);
|
$response = $controller->didProcessRequest($response);
|
||||||
$response = $application->willSendResponse($response, $controller);
|
$response = $application->willSendResponse($response, $controller);
|
||||||
$response->setRequest($request);
|
$response->setRequest($request);
|
||||||
$response_string = $response->buildResponseString();
|
|
||||||
|
$sink->writeResponse($response);
|
||||||
|
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
$write_guard->dispose();
|
$write_guard->dispose();
|
||||||
if ($access_log) {
|
if ($access_log) {
|
||||||
|
@ -119,18 +122,6 @@ try {
|
||||||
|
|
||||||
$write_guard->dispose();
|
$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) {
|
if ($access_log) {
|
||||||
$request_start = PhabricatorStartup::getStartTime();
|
$request_start = PhabricatorStartup::getStartTime();
|
||||||
$access_log->setData(
|
$access_log->setData(
|
||||||
|
|
Loading…
Reference in a new issue