You are here

function _imagecache_cache_set_cache_headers in ImageCache 5.2

Same name and namespace in other branches
  1. 6.2 imagecache.module \_imagecache_cache_set_cache_headers()

Set file headers that handle "If-Modified-Since" correctly for the given fileinfo. Most code has been taken from drupal_page_cache_header().

1 call to _imagecache_cache_set_cache_headers()
imagecache_transfer in ./imagecache.module
helper function to transfer files from imagecache. Determines mime type and sets a last modified header.

File

./imagecache.module, line 418
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;
}