- 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.4.3.x
parent
069e1bb87b
commit
b8416f613a
|
@ -1046,19 +1046,21 @@ function drupal_page_header() {
|
||||||
|
|
||||||
if (variable_get("cache", 0)) {
|
if (variable_get("cache", 0)) {
|
||||||
if ($cache = page_get_cache()) {
|
if ($cache = page_get_cache()) {
|
||||||
|
|
||||||
|
// Set default values:
|
||||||
$date = gmdate("D, d M Y H:i:s", $cache->created) ." GMT";
|
$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("Last-Modified: $date");
|
||||||
header("ETag: \"$date\"");
|
header("ETag: $etag");
|
||||||
if (function_exists("getallheaders") && $headers = getallheaders()) {
|
if ($modified_since && $none_match) {
|
||||||
/*
|
header("HTTP/1.0 304 Not Modified");
|
||||||
** Notice that the above is an optional Apache-ism so for the
|
exit();
|
||||||
** 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print $cache->data;
|
print $cache->data;
|
||||||
|
|
Loading…
Reference in New Issue