Index: admin_menu.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/admin_menu/admin_menu.module,v
retrieving revision 1.43.2.17.2.11
diff -u -p -r1.43.2.17.2.11 admin_menu.module
--- admin_menu.module	12 Jun 2009 01:34:06 -0000	1.43.2.17.2.11
+++ admin_menu.module	16 Jun 2009 16:59:12 -0000
@@ -282,18 +282,54 @@ function admin_menu_js_cache($hash = NUL
 
   // @todo According to http://www.mnot.net/blog/2006/05/11/browser_caching,
   //   IE will only cache the content when it is compressed.
-  // Determine if the client accepts gzipped data.
-  if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && function_exists('gzencode')) {
-    if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) {
-      $encoding = 'gzip';
-    }
-    elseif (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== FALSE) {
+  // Determine if the client accepts gzipped data (quicker than other checks).
+  if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
+    if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== FALSE) {
       $encoding = 'x-gzip';
     }
+    elseif (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) {
+      $encoding = 'gzip';
+    }
     if (!empty($encoding)) {
-      header('Vary: Accept-Encoding');
-      header('Content-Encoding: ' . $encoding);
-      $content = gzencode($content, 9, FORCE_GZIP);
+
+      // The site administrator may have disabled Drupal page compression,
+      // for example to perform this task at web server level, using Apache
+      // mod_deflate, etc. So let's follow the same pattern used by Drupal
+      // itself here. When page compression is performed by the web server,
+      // then it is also responsible to generate the proper headers.
+      if (variable_get('page_compression', TRUE)) {
+
+        // Ok, now that we know the user agent supports compression, and Drupal
+        // has page compression enabled, let's see if this PHP installation has
+        // the zlib extension loaded.
+        if (extension_loaded('zlib')) {
+
+          // Good, now we may not need to perform the compression if the zlib
+          // extension is not only loaded, but also the zlib.output_compression
+          // option enabled.
+          if (zlib_get_coding_type() === FALSE) {
+
+            // Ok, when we reach this point, we should be safe to perform gzip
+            // compression because we know:
+            // a) The user agent is telling us it supports gzip compression.
+            // b) Drupal has page compression enabled.
+            // c) The PHP zlib extension is loaded, but automatic compression
+            //    is not enabled (zlib.output_compression = Off).
+
+            // Vary header is included to tell caches to keep separate versions of
+            // the admin menu based on user agent capabilities.
+            header('Vary: Accept-Encoding');
+
+            // No one else performed the compression, so if we do, we are also the
+            // one who is responsible to generate the header that will tell the
+            // user agent we are sending gzip compressed content.
+            header('Content-Encoding: ' . $encoding);
+
+            // Finally, just do it.
+            $content = gzencode($content, 9, FORCE_GZIP);
+          }
+        }
+      }
     }
   }
 
