From 153cb6d30510f9804fe596ac6777bc2f35111ae2 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 17 Aug 2017 14:40:21 +0300 Subject: add support for http 304 not modified (no timestamp calculation bullshit like last time) --- classes/rssutils.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'classes/rssutils.php') diff --git a/classes/rssutils.php b/classes/rssutils.php index b6693b8c2..460709f05 100644 --- a/classes/rssutils.php +++ b/classes/rssutils.php @@ -292,7 +292,8 @@ class RSSUtils { $result = db_query("SELECT id,update_interval,auth_login, feed_url,auth_pass,cache_images, mark_unread_on_update, owner_uid, - auth_pass_encrypted, feed_language + auth_pass_encrypted, feed_language, + last_modified FROM ttrss_feeds WHERE id = '$feed'"); $owner_uid = db_fetch_result($result, 0, "owner_uid"); @@ -312,6 +313,7 @@ class RSSUtils { $auth_pass = decrypt_string($auth_pass); } + $stored_last_modified = db_fetch_result($result, 0, "last_modified"); $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images")); $fetch_url = db_fetch_result($result, 0, "feed_url"); $feed_language = db_escape_string(mb_strtolower(db_fetch_result($result, 0, "feed_language"))); @@ -359,18 +361,33 @@ class RSSUtils { _debug("local cache will not be used for this feed", $debug_enabled); } + global $fetch_last_modified; + // fetch feed from source if (!$feed_data) { + _debug("stored last modified: $stored_last_modified", $debug_enabled); _debug("fetching [$fetch_url]...", $debug_enabled); if (ini_get("open_basedir") && function_exists("curl_init")) { _debug("not using CURL due to open_basedir restrictions"); } - $feed_data = fetch_file_contents($fetch_url, false, + /*$feed_data = fetch_file_contents($fetch_url, false, $auth_login, $auth_pass, false, $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT, - 0); + 0);*/ + + // TODO: last_modified should be limited, if the feed has not been updated for a while + // we probably should force one update without the header + // unfortunately last_updated gets bumped on http 304 so that daemon would work properly + + $feed_data = fetch_file_contents([ + "url" => $fetch_url, + "login" => $auth_login, + "pass" => $auth_pass, + "timeout" => $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT, + "last_modified" => $force_refetch ? "" : $stored_last_modified + ]); global $fetch_curl_used; @@ -383,6 +400,14 @@ class RSSUtils { $feed_data = trim($feed_data); _debug("fetch done.", $debug_enabled); + _debug("source last modified: " . $fetch_last_modified); + + if ($feed_data && $fetch_last_modified != $stored_last_modified) { + $last_modified_escaped = db_escape_string(substr($fetch_last_modified, 0, 245)); + + db_query("UPDATE ttrss_feeds SET last_modified = '$last_modified_escaped' WHERE id = '$feed'"); + + } // cache vanilla feed data for re-use if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/simplepie")) { -- cgit v1.2.3