Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/configuration/AphrontApplicationConfiguration.php
| Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | abstract class AphrontApplicationConfiguration { | ||||
| final public function getPath() { | final public function getPath() { | ||||
| return $this->path; | return $this->path; | ||||
| } | } | ||||
| public function willBuildRequest() {} | public function willBuildRequest() {} | ||||
| /** | |||||
| * @phutil-external-symbol class PhabricatorStartup | |||||
| */ | |||||
| public static function runHTTPRequest(AphrontHTTPSink $sink) { | |||||
| PhabricatorEnv::initializeWebEnvironment(); | |||||
| $debug_time_limit = PhabricatorEnv::getEnvConfig('debug.time-limit'); | |||||
| if ($debug_time_limit) { | |||||
| PhabricatorStartup::setDebugTimeLimit($debug_time_limit); | |||||
| } | |||||
| // This is the earliest we can get away with this, we need env config first. | |||||
| PhabricatorAccessLog::init(); | |||||
| $access_log = PhabricatorAccessLog::getLog(); | |||||
| PhabricatorStartup::setGlobal('log.access', $access_log); | |||||
| $access_log->setData( | |||||
| array( | |||||
| 'R' => AphrontRequest::getHTTPHeader('Referer', '-'), | |||||
| 'r' => idx($_SERVER, 'REMOTE_ADDR', '-'), | |||||
| 'M' => idx($_SERVER, 'REQUEST_METHOD', '-'), | |||||
| )); | |||||
| DarkConsoleXHProfPluginAPI::hookProfiler(); | |||||
| DarkConsoleErrorLogPluginAPI::registerErrorHandler(); | |||||
| $response = PhabricatorSetupCheck::willProcessRequest(); | |||||
| if ($response) { | |||||
| PhabricatorStartup::endOutputCapture(); | |||||
| $sink->writeResponse($response); | |||||
| return; | |||||
| } | |||||
| $host = AphrontRequest::getHTTPHeader('Host'); | |||||
| $path = $_REQUEST['__path__']; | |||||
| switch ($host) { | |||||
| default: | |||||
| $config_key = 'aphront.default-application-configuration-class'; | |||||
| $application = PhabricatorEnv::newObjectFromConfig($config_key); | |||||
| break; | |||||
| } | |||||
| $application->setHost($host); | |||||
| $application->setPath($path); | |||||
| $application->willBuildRequest(); | |||||
| $request = $application->buildRequest(); | |||||
| // Build the server URI implied by the request headers. If an administrator | |||||
| // has not configured "phabricator.base-uri" yet, we'll use this to generate | |||||
| // links. | |||||
| $request_protocol = ($request->isHTTPS() ? 'https' : 'http'); | |||||
| $request_base_uri = "{$request_protocol}://{$host}/"; | |||||
btrahan: I know this is just a move, but doesn't this code block always run even if an administrator… | |||||
Not Done Inline ActionsYeah. The "request base URI" is "the base URI which is implied by the request headers", and does not override "phabricator.base-uri". A better name might be "setFallbackBaseURI()" or something, maybe. Calls like getURI() and getProductionURI() basically go: if (phabricator.base-uri is set) {
use that;
}
if (the "request base URI" is set) {
use that;
}
throw an exception;epriestley: Yeah. The "request base URI" is "the base URI which is implied by the request headers", and… | |||||
| PhabricatorEnv::setRequestBaseURI($request_base_uri); | |||||
| $access_log->setData( | |||||
| array( | |||||
| 'U' => (string)$request->getRequestURI()->getPath(), | |||||
| )); | |||||
| $write_guard = new AphrontWriteGuard(array($request, 'validateCSRF')); | |||||
| $processing_exception = null; | |||||
| try { | |||||
| $response = $application->processRequest($request, $access_log, $sink); | |||||
| $response_code = $response->getHTTPResponseCode(); | |||||
| } catch (Exception $ex) { | |||||
| $processing_exception = $ex; | |||||
| $response_code = 500; | |||||
| } | |||||
| $write_guard->dispose(); | |||||
| $access_log->setData( | |||||
| array( | |||||
| 'c' => $response_code, | |||||
| 'T' => PhabricatorStartup::getMicrosecondsSinceStart(), | |||||
| )); | |||||
| $access_log->write(); | |||||
| DarkConsoleXHProfPluginAPI::saveProfilerSample($access_log); | |||||
| // Add points to the rate limits for this request. | |||||
| if (isset($_SERVER['REMOTE_ADDR'])) { | |||||
| $user_ip = $_SERVER['REMOTE_ADDR']; | |||||
| // The base score for a request allows users to make 30 requests per | |||||
| // minute. | |||||
| $score = (1000 / 30); | |||||
| // If the user was logged in, let them make more requests. | |||||
| if ($request->getUser() && $request->getUser()->getPHID()) { | |||||
| $score = $score / 5; | |||||
| } | |||||
| PhabricatorStartup::addRateLimitScore($user_ip, $score); | |||||
| } | |||||
| if ($processing_exception) { | |||||
| throw $processing_exception; | |||||
| } | |||||
| } | |||||
| public function processRequest( | |||||
| AphrontRequest $request, | |||||
| PhutilDeferredLog $access_log, | |||||
| AphrontHTTPSink $sink) { | |||||
| $this->setRequest($request); | |||||
| list($controller, $uri_data) = $this->buildController(); | |||||
| $access_log->setData( | |||||
| array( | |||||
| 'C' => get_class($controller), | |||||
| )); | |||||
| $request->setURIMap($uri_data); | |||||
| $controller->setRequest($request); | |||||
| // If execution throws an exception and then trying to render that | |||||
| // exception throws another exception, we want to show the original | |||||
| // exception, as it is likely the root cause of the rendering exception. | |||||
| $original_exception = null; | |||||
| try { | |||||
| $response = $controller->willBeginExecution(); | |||||
| if ($request->getUser() && $request->getUser()->getPHID()) { | |||||
| $access_log->setData( | |||||
| array( | |||||
| 'u' => $request->getUser()->getUserName(), | |||||
| 'P' => $request->getUser()->getPHID(), | |||||
| )); | |||||
| } | |||||
| if (!$response) { | |||||
| $controller->willProcessRequest($uri_data); | |||||
| $response = $controller->handleRequest($request); | |||||
| } | |||||
| } catch (Exception $ex) { | |||||
| $original_exception = $ex; | |||||
| $response = $this->handleException($ex); | |||||
| } | |||||
| try { | |||||
| $response = $controller->didProcessRequest($response); | |||||
| $response = $this->willSendResponse($response, $controller); | |||||
| $response->setRequest($request); | |||||
| $unexpected_output = PhabricatorStartup::endOutputCapture(); | |||||
| if ($unexpected_output) { | |||||
| $unexpected_output = pht( | |||||
| "Unexpected output:\n\n%s", | |||||
| $unexpected_output); | |||||
| phlog($unexpected_output); | |||||
| if ($response instanceof AphrontWebpageResponse) { | |||||
| echo phutil_tag( | |||||
| 'div', | |||||
| array('style' => | |||||
| 'background: #eeddff;'. | |||||
| 'white-space: pre-wrap;'. | |||||
| 'z-index: 200000;'. | |||||
| 'position: relative;'. | |||||
| 'padding: 8px;'. | |||||
| 'font-family: monospace', | |||||
| ), | |||||
| $unexpected_output); | |||||
| } | |||||
| } | |||||
| $sink->writeResponse($response); | |||||
| } catch (Exception $ex) { | |||||
| if ($original_exception) { | |||||
| throw $original_exception; | |||||
| } | |||||
| throw $ex; | |||||
| } | |||||
| return $response; | |||||
| } | |||||
| /* -( URI Routing )-------------------------------------------------------- */ | /* -( URI Routing )-------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * Using builtin and application routes, build the appropriate | * Using builtin and application routes, build the appropriate | ||||
| * @{class:AphrontController} class for the request. To route a request, we | * @{class:AphrontController} class for the request. To route a request, we | ||||
| * first test if the HTTP_HOST is configured as a valid Phabricator URI. If | * first test if the HTTP_HOST is configured as a valid Phabricator URI. If | ||||
| * it isn't, we do a special check to see if it's a custom domain for a blog | * it isn't, we do a special check to see if it's a custom domain for a blog | ||||
| ▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines | |||||
I know this is just a move, but doesn't this code block always run even if an administrator sets base-uri?