From b8416f613a0db27c63aa92321a5cb537beb46c54 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 28 Sep 2003 17:21:57 +0000 Subject: - Made the check for If-Modified-Since and Etag headers work for non-Apache webservers. This will, for example, improve caching on IIS. Patch by Kjartan. --- includes/common.inc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'includes/common.inc') diff --git a/includes/common.inc b/includes/common.inc index 64c536b43..f84aceedc 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1046,19 +1046,21 @@ function drupal_page_header() { if (variable_get("cache", 0)) { if ($cache = page_get_cache()) { + + // Set default values: $date = gmdate("D, d M Y H:i:s", $cache->created) ." GMT"; + $etag = '"'. md5($date) .'"'; + + // Check http headers: + $modified_since = isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) ? $_SERVER["HTTP_IF_MODIFIED_SINCE"] == $date : true; + $none_match = isset($_SERVER["HTTP_IF_NONE_MATCH"]) ? $_SERVER["HTTP_IF_NONE_MATCH"] == $etag : true; + + // Send appropriate response: header("Last-Modified: $date"); - header("ETag: \"$date\""); - if (function_exists("getallheaders") && $headers = getallheaders()) { - /* - ** Notice that the above is an optional Apache-ism so for the - ** time being we don't send 304 headers when "getallheaders()" - ** is not supported (eg. on IIS webservers). - */ - if ($headers["If-Modified-Since"] == $date && $headers["If-None-Match"] == "\"$date\"") { - header("HTTP/1.0 304 Not Modified"); - exit(); - } + header("ETag: $etag"); + if ($modified_since && $none_match) { + header("HTTP/1.0 304 Not Modified"); + exit(); } print $cache->data; -- cgit v1.2.3