mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-22 20:51:10 +01:00
Route hard-coded "/favicon.ico" requests to a favicon resource
Summary: See PHI1719. User agents making hard-coded requests to "/favicon.ico" currently 404. This is a mild source of log noise, and we can reasonably route this request. Limitations: - This only routes the "PlatformSite". Other sites (custom Phame blogs, third-party sites, Phurl redirectors) won't route here for now. - This returns a "Location:" redirect to the correct resource rather than icon data directly. This produces the right icon with the right caching behavior, and returning icon data directly is difficult in the general case. However, it won't perform/cache as well as a direct response would. Test Plan: - Visted `/favicon.ico`. - Before: 404. - After: redirect to favicon. Differential Revision: https://secure.phabricator.com/D21195
This commit is contained in:
parent
304467feb2
commit
65a2b5e219
3 changed files with 39 additions and 0 deletions
|
@ -3371,6 +3371,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFactRaw' => 'applications/fact/storage/PhabricatorFactRaw.php',
|
||||
'PhabricatorFactUpdateIterator' => 'applications/fact/extract/PhabricatorFactUpdateIterator.php',
|
||||
'PhabricatorFailHisecUserLogType' => 'applications/people/userlog/PhabricatorFailHisecUserLogType.php',
|
||||
'PhabricatorFaviconController' => 'applications/system/controller/PhabricatorFaviconController.php',
|
||||
'PhabricatorFaviconRef' => 'applications/files/favicon/PhabricatorFaviconRef.php',
|
||||
'PhabricatorFaviconRefQuery' => 'applications/files/favicon/PhabricatorFaviconRefQuery.php',
|
||||
'PhabricatorFavoritesApplication' => 'applications/favorites/application/PhabricatorFavoritesApplication.php',
|
||||
|
@ -9852,6 +9853,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFactRaw' => 'PhabricatorFactDAO',
|
||||
'PhabricatorFactUpdateIterator' => 'PhutilBufferedIterator',
|
||||
'PhabricatorFailHisecUserLogType' => 'PhabricatorUserLogType',
|
||||
'PhabricatorFaviconController' => 'PhabricatorController',
|
||||
'PhabricatorFaviconRef' => 'Phobject',
|
||||
'PhabricatorFaviconRefQuery' => 'Phobject',
|
||||
'PhabricatorFavoritesApplication' => 'PhabricatorApplication',
|
||||
|
|
|
@ -24,6 +24,7 @@ final class PhabricatorSystemApplication extends PhabricatorApplication {
|
|||
return array(
|
||||
'/status/' => 'PhabricatorStatusController',
|
||||
'/debug/' => 'PhabricatorDebugController',
|
||||
'/favicon.ico' => 'PhabricatorFaviconController',
|
||||
'/robots.txt' => 'PhabricatorRobotsController',
|
||||
'/services/' => array(
|
||||
'encoding/' => 'PhabricatorSystemSelectEncodingController',
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorFaviconController
|
||||
extends PhabricatorController {
|
||||
|
||||
public function shouldRequireLogin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
// See PHI1719. Phabricator uses "<link /"> tags in the document body
|
||||
// to direct user agents to icons, like this:
|
||||
//
|
||||
// <link rel="icon" href="..." />
|
||||
//
|
||||
// However, some software requests the hard-coded path "/favicon.ico"
|
||||
// directly. To tidy the logs, serve some reasonable response rather than
|
||||
// a 404.
|
||||
|
||||
// NOTE: Right now, this only works for the "PhabricatorPlatformSite".
|
||||
// Other sites (like custom Phame blogs) won't currently route this
|
||||
// path.
|
||||
|
||||
$ref = id(new PhabricatorFaviconRef())
|
||||
->setWidth(64)
|
||||
->setHeight(64);
|
||||
|
||||
id(new PhabricatorFaviconRefQuery())
|
||||
->withRefs(array($ref))
|
||||
->execute();
|
||||
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setIsExternal(true)
|
||||
->setURI($ref->getURI());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue