--- cacherouter_original.inc	2008-06-02 04:04:34.000000000 +0200
+++ cacherouter.inc	2008-10-24 17:16:19.000000000 +0200
@@ -99,11 +99,11 @@ function cache_set($cid, $value, $table 
 function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {
   global $cache;
   global $user;
-  
+
   if (!isset($cache)) {
     $cache = new CacheRouter();
   }
-  
+
   if (!isset($cid) && !isset($table)) {
     // Clear the block cache first, so stale data will
     // not end up in the page cache.
@@ -111,7 +111,7 @@ function cache_clear_all($cid = NULL, $t
     $cache->flush('cache_page');
     return;
   }
-  
+
   if (empty($cid)) {
     if (variable_get('cache_lifetime', 0)) {
       // We store the time in the current user's $user->cache variable which
@@ -150,7 +150,7 @@ function cache_clear_all($cid = NULL, $t
       $cache->delete($cid, $table);
     }
   }
-  
+
 }
 
 /**
@@ -167,9 +167,21 @@ function page_cache_fastpath() {
       $page = $cache->get($base_root . request_uri(), 'cache_page');
       if (!empty($page)) {
         drupal_page_header();
-        if (function_exists('gzencode')) {
-          header('Content-Encoding: gzip');
+        
+         //checking if first chars are compressed (always the same pattern for every header)
+        if (substr($page->data, 0,3) == "\x1f\x8b\x08") {
+          
+          // Determine if the browser accepts gzipped data.
+          if (@strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === FALSE && function_exists('gzencode')) {
+            // Strip the gzip header and run uncompress.
+            $page->data = gzinflate(substr(substr($page->data, 10), 0, -8));
+          }
+          elseif (function_exists('gzencode')) {
+            //send gzip header to the browser
+            header('Content-Encoding: gzip');
+          }
         }
+        
         print $page->data;
         return TRUE;
       }
