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) --- include/functions.php | 61 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 17 deletions(-) (limited to 'include/functions.php') diff --git a/include/functions.php b/include/functions.php index dc2e9f64d..8ea8719ca 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ array( 'method' => 'GET', 'ignore_errors' => true, 'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT, 'protocol_version'=> 1.1, - 'header' => "If-Modified-Since: ".gmdate("D, d M Y H:i:s \\G\\M\\T\r\n", $timestamp) - ))); + 'header' => "If-Modified-Since: $last_modified\r\n") + )); } else { $context = stream_context_create(array( 'http' => array( @@ -497,10 +518,16 @@ if (isset($http_response_header) && is_array($http_response_header)) { foreach ($http_response_header as $h) { - if (substr(strtolower($h), 0, 13) == 'content-type:') { - $fetch_last_content_type = substr($h, 14); + list ($key, $value) = explode(": ", $h); + + $key = strtolower($key); + + if ($key == 'content-type') { + $fetch_last_content_type = $value; // don't abort here b/c there might be more than one // e.g. if we were being redirected -- last one is the right one + } else if ($key == 'last-modified') { + $fetch_last_modified = $value; } if (substr(strtolower($h), 0, 7) == 'http/1.') { -- cgit v1.2.3