aboutsummaryrefslogtreecommitdiff
path: root/p/f.php
diff options
context:
space:
mode:
authorGravatar Pablo Caro <me@pcaro.es> 2020-06-06 23:29:46 +0200
committerGravatar GitHub <noreply@github.com> 2020-06-06 23:29:46 +0200
commit138d9ca6587b1c6bcc656ad58a5db03492ae9f12 (patch)
tree9ffa9cda5095ca763221d4adbcb6660342cb1b41 /p/f.php
parentb2b249d6d6e1339b7a55a61ac06b0520b9dc91b9 (diff)
Return the correct Content-Type for SVG favicons (#3032)
* Return the correct Content-Type for SVG favicons * Use mime_content_type to check file type * Use tab instead of spaces * Remove extra blank lines Co-authored-by: Frans de Jonge <fransdejonge@gmail.com> * Update f.php * Better obey HTTP/1.1 304 Not Modified rules about headers https://tools.ietf.org/html/rfc2616#section-10.3.5 * Do not fail if the optional `fileinfo` is not available * Handle more cases such as PNG, GIF, BMP... * Add Content-Type for default favicon * Do not repeat HTTP headers in HTTP 304 response According to https://tools.ietf.org/html/rfc2616#section-10.3.5 it is better not to repeat HTTP headers in a HTTP 304 Not Modified response Co-authored-by: Frans de Jonge <fransdejonge@gmail.com> Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'p/f.php')
-rw-r--r--p/f.php19
1 files changed, 13 insertions, 6 deletions
diff --git a/p/f.php b/p/f.php
index 9947539c3..d856256aa 100644
--- a/p/f.php
+++ b/p/f.php
@@ -5,10 +5,10 @@ require(LIB_PATH . '/favicons.php');
require(LIB_PATH . '/http-conditional.php');
function show_default_favicon($cacheSeconds = 3600) {
- header('Content-Disposition: inline; filename="default_favicon.ico"');
-
$default_mtime = @filemtime(DEFAULT_FAVICON);
if (!httpConditional($default_mtime, $cacheSeconds, 2)) {
+ header('Content-Type: image/x-icon');
+ header('Content-Disposition: inline; filename="default_favicon.ico"');
readfile(DEFAULT_FAVICON);
}
}
@@ -24,8 +24,6 @@ $ico = FAVICONS_DIR . $id . '.ico';
$ico_mtime = @filemtime($ico);
$txt_mtime = @filemtime($txt);
-header('Content-Type: image/x-icon');
-
if ($ico_mtime == false || $ico_mtime < $txt_mtime || ($ico_mtime < time() - (mt_rand(15, 20) * 86400))) {
if ($txt_mtime == false) {
show_default_favicon(1800);
@@ -45,8 +43,17 @@ if ($ico_mtime == false || $ico_mtime < $txt_mtime || ($ico_mtime < time() - (mt
}
}
-header('Content-Disposition: inline; filename="' . $id . '.ico"');
-
if (!httpConditional($ico_mtime, mt_rand(14, 21) * 86400, 2)) {
+ $ico_content_type = 'image/x-icon';
+ if (function_exists('mime_content_type')) {
+ $ico_content_type = mime_content_type($ico);
+ }
+ switch ($ico_content_type) {
+ case 'image/svg':
+ $ico_content_type = 'image/svg+xml';
+ break;
+ }
+ header('Content-Type: ' . $ico_content_type);
+ header('Content-Disposition: inline; filename="' . $id . '.ico"');
readfile($ico);
}