@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+9 -15
+4 -1
src/aphront/sink/AphrontHTTPSink.php
··· 96 96 * @return void 97 97 */ 98 98 final public function writeResponse(AphrontResponse $response) { 99 + // Do this first, in case it throws. 100 + $response_string = $response->buildResponseString(); 101 + 99 102 $all_headers = array_merge( 100 103 $response->getHeaders(), 101 104 $response->getCacheHeaders()); 102 105 103 106 $this->writeHTTPStatus($response->getHTTPResponseCode()); 104 107 $this->writeHeaders($all_headers); 105 - $this->writeData($response->buildResponseString()); 108 + $this->writeData($response_string); 106 109 } 107 110 108 111
+5 -14
webroot/index.php
··· 26 26 PhutilErrorHandler::setErrorListener( 27 27 array('DarkConsoleErrorLogPluginAPI', 'handleErrors')); 28 28 29 + $sink = new AphrontPHPHTTPSink(); 30 + 29 31 if (PhabricatorEnv::getEnvConfig('phabricator.setup')) { 30 32 try { 31 33 PhabricatorSetup::runSetup(); ··· 47 49 $application = PhabricatorEnv::newObjectFromConfig($config_key); 48 50 break; 49 51 } 50 - 51 52 52 53 $application->setHost($host); 53 54 $application->setPath($path); ··· 100 101 $response = $controller->didProcessRequest($response); 101 102 $response = $application->willSendResponse($response, $controller); 102 103 $response->setRequest($request); 103 - $response_string = $response->buildResponseString(); 104 + 105 + $sink->writeResponse($response); 106 + 104 107 } catch (Exception $ex) { 105 108 $write_guard->dispose(); 106 109 if ($access_log) { ··· 118 121 } 119 122 120 123 $write_guard->dispose(); 121 - 122 - // TODO: Share the $sink->writeResponse() pathway here? 123 - 124 - $sink = new AphrontPHPHTTPSink(); 125 - $sink->writeHTTPStatus($response->getHTTPResponseCode()); 126 - 127 - $headers = $response->getCacheHeaders(); 128 - $headers = array_merge($headers, $response->getHeaders()); 129 - 130 - $sink->writeHeaders($headers); 131 - 132 - $sink->writeData($response_string); 133 124 134 125 if ($access_log) { 135 126 $request_start = PhabricatorStartup::getStartTime();