function _imagecache_cache_set_cache_headers in ImageCache 6.2
Same name and namespace in other branches
- 5.2 imagecache.module \_imagecache_cache_set_cache_headers()
Set file headers that handle "If-Modified-Since" correctly for the given fileinfo.
Note that this function may return or may call exit().
Most code has been taken from drupal_page_cache_header().
Parameters
$fileinfo: Array returned by stat().
Array of existing headers.:
Return value
Nothing but beware that this function may not return.
1 call to _imagecache_cache_set_cache_headers()
- imagecache_transfer in ./
imagecache.module - Helper function to transfer files from imagecache.
File
- ./
imagecache.module, line 555 - Dynamic image resizer and image cacher.
Code
function _imagecache_cache_set_cache_headers($fileinfo, &$headers) {
// Set default values:
$last_modified = gmdate('D, d M Y H:i:s', $fileinfo[9]) . ' GMT';
$etag = '"' . md5($last_modified) . '"';
// See if the client has provided the required HTTP headers:
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) : FALSE;
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : FALSE;
if ($if_modified_since && $if_none_match && $if_none_match == $etag && $if_modified_since == $last_modified) {
// if-modified-since must match
header('HTTP/1.1 304 Not Modified');
// All 304 responses must send an etag if the 200 response
// for the same object contained an etag
header('Etag: ' . $etag);
// We must also set Last-Modified again, so that we overwrite Drupal's
// default Last-Modified header with the right one
header('Last-Modified: ' . $last_modified);
exit;
}
// Send appropriate response:
$headers[] = 'Last-Modified: ' . $last_modified;
$headers[] = 'ETag: ' . $etag;
}