4
0
Эх сурвалжийг харах

Serve HTTP cache for default favicon + better headers

See https://github.com/FreshRSS/FreshRSS/commit/da7d34d2ef45e4cfcf1410a279998f680a6338ea#commitcomment-9439610
Marien Fressinaud 11 жил өмнө
parent
commit
f5043dbf71
1 өөрчлөгдсөн 14 нэмэгдсэн , 6 устгасан
  1. 14 6
      p/f.php

+ 14 - 6
p/f.php

@@ -4,6 +4,7 @@ require('../constants.php');
 
 include(LIB_PATH . '/Favicon/Favicon.php');
 include(LIB_PATH . '/Favicon/DataAccess.php');
+require(LIB_PATH . '/http-conditional.php');
 
 
 $favicons_dir = DATA_PATH . '/favicons/';
@@ -46,9 +47,13 @@ function download_favicon($website, $dest) {
 function show_default_favicon() {
 	global $default_favicon;
 
-	header('Content-Type: image/ico');
-	readfile($default_favicon);
-	die();
+	header('Content-Type: image/x-icon');
+	header('Content-Disposition: inline; filename="default_favicon.ico"');
+
+	$default_mtime = @filemtime($default_favicon);
+	if (!httpConditional($default_mtime, 2592000, 2)) {
+		readfile($default_favicon);
+	}
 }
 
 
@@ -63,19 +68,22 @@ $ico = $favicons_dir . $id . '.ico';
 $ico_mtime = @filemtime($ico);
 $txt_mtime = @filemtime($txt);
 
-if (($ico_mtime == false) || ($txt_mtime > $ico_mtime)) {
+
+if ($ico_mtime == false || $txt_mtime > $ico_mtime) {
 	if ($txt_mtime == false) {
 		show_default_favicon();
+		return;
 	}
 
+	// no ico file or we should download a new one.
 	$url = file_get_contents($txt);
 	if (!download_favicon($url, $ico)) {
+		// Download failed, show the default favicon
 		show_default_favicon();
+		return;
 	}
 }
 
-require(LIB_PATH . '/http-conditional.php');
-
 header('Content-Type: image/x-icon');
 header('Content-Disposition: inline; filename="' . $id . '.ico"');