--- image.module	2008-04-18 10:33:34.000000000 +1000
+++ image.module.new	2009-02-04 15:17:36.000000000 +1100
@@ -394,10 +394,36 @@ function image_file_download($filename) 
         $images = (array) $node->images;
         unset($images[IMAGE_ORIGINAL]);
         if (user_access('view original images') || in_array($filepath, $images)) {
-          return array(
-            'Content-Type: '. mime_header_encode($file->filemime),
-            'Content-Length: '. (int) $file->filesize,
-          );
+          // Apache specific patch for not-modified
+          $modified = filemtime($filepath);
+   
+          $request = getallheaders();
+
+          if (isset($request['If-Modified-Since'])) {
+            //remove information after the semicolon and form a timestamp
+            $request_modified = explode(';', $request['If-Modified-Since']);
+            $request_modified = strtotime($request_modified[0]);
+          }
+
+          //enable caching on this url for proxy servers
+          $offset = 60*60*24*30; // one month
+          $headers = array('Content-Type: ' . mime_header_encode($file->filemime),
+                           'Content-Length: '. (int) $file->filesize,
+                           'Last-Modified: ' . gmdate('D, d M Y H:i:s', $modified) . ' GMT',
+                           'Expires: '. gmdate('D, d M Y H:i:s', time() + $offset) .' GMT',
+                           'Cache-Control: public');
+
+          // Compare the mtime on the request to the mtime of the image file
+          if ($modified <= $request_modified) {
+            $headers[] = 'HTTP/1.1 304 Not Modified';
+            foreach ($headers as $header) {
+              header($header);
+            }
+            exit();
+          }
+
+          apache_setenv('no-gzip', '1');
+          return $headers;
         }
       }
       return -1;
