 resumable_download.inc | 50 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 3 deletions(-)

diff --git a/resumable_download.inc b/resumable_download.inc
index 426c385..90e614b 100644
--- a/resumable_download.inc
+++ b/resumable_download.inc
@@ -21,11 +21,53 @@ function _resumable_download_download() {
   $uri = $priv_or_pub . '://' . $filepath;
   $filepath = drupal_realpath($uri);
 
-  if (file_exists($filepath)) {
+  if (file_exists($filepath)) {    // <- did you notice that this check ist case sensitive, while the later download is case intensive?
     $headers = module_invoke_all('file_download', $uri);
-    if (in_array(-1, $headers)) {
+	if (in_array(-1, $headers)) {
       return drupal_access_denied();
     }
+
+	// Check for modificatio0n of the file
+
+	// first we need to know: does the browser request include modification check?
+	if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
+
+	// read timestamp the browser tell us
+    $ifs = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
+      
+		// get timestamp of the file on our server     
+		$modified = filemtime($filepath);
+		if($modified == $ifs) {
+		
+			// check etag too, when the request contains it
+			if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
+			
+				$ifsn = ($_SERVER['HTTP_IF_NONE_MATCH']);
+				$filesizeb = filesize($filepath);
+				$eetag = (dechex(fileinode($filepath)) . '-' . dechex($modified) . '-' . dechex($filesizeb));
+				
+				// compare etag sent by browser with etag generated with the file			
+				if($ifsn == $eetag) {
+				
+					// set header to 304 and exit
+					header('HTTP/1.1 304 Not Modified'); 
+					resumable_download_drupal_add_http_header('Last-Modified', gmdate('D, d M Y H:i:s', $modified) . ' GMT');
+					resumable_download_drupal_add_http_header('ETag', dechex(fileinode($filepath)) . '-' . dechex($modified) . '-' . dechex($filesizeb));
+					drupal_exit();
+				}
+			}
+			else{
+				$filesizeb = filesize($filepath);
+				// set header to 304 and exit
+				header('HTTP/1.1 304 Not Modified');                        
+				resumable_download_drupal_add_http_header('Last-Modified', gmdate('D, d M Y H:i:s', $modified) . ' GMT');
+				resumable_download_drupal_add_http_header('ETag', dechex(fileinode($filepath)) . '-' . dechex($modified) . '-' . dechex($filesizeb));
+				drupal_exit();
+		}
+	}
+}
+
+    
     if (count($headers)) {
 	  $max_speed = variable_get('resumable_download_max_speed', NULL);
 	  if (user_access('bypass download speed limit')) {
@@ -41,6 +83,7 @@ function _resumable_download($source, $headers, $max_speed = NULL) {
   if (ob_get_level()) {
     ob_end_clean();
   }
+
   
   // IE cannot download private files because it cannot store files downloaded
   // over https in the browser cache. The problem can be solved by sending
@@ -74,6 +117,7 @@ function _resumable_download($source, $headers, $max_speed = NULL) {
 	
     $valid = FALSE;
     $satisfiable = FALSE;
+
     // Is this a partial request?
 	
     if (isset($_SERVER['HTTP_RANGE'])) {
@@ -247,4 +291,4 @@ function resumable_download_transfer_range($fd, $length, $byte = 0, $max_speed =
 */
 function resumable_download_drupal_add_http_header($name, $value, $append = FALSE) {
   return drupal_add_http_header($name, $value, $append);  
-}
\ No newline at end of file
+}
