GZIP files served by the development server.

Mojo application can usually be reduced to approximately a third of
their sizes.

R=ppi@chromium.org

Review URL: https://codereview.chromium.org/1247573003 .
diff --git a/mojo/devtools/common/devtoolslib/http_server.py b/mojo/devtools/common/devtoolslib/http_server.py
index ec6973d..c01928a 100644
--- a/mojo/devtools/common/devtoolslib/http_server.py
+++ b/mojo/devtools/common/devtoolslib/http_server.py
@@ -6,10 +6,12 @@
 import datetime
 import email.utils
 import errno
+import gzip
 import hashlib
 import logging
 import math
 import os.path
+import shutil
 import socket
 import threading
 
@@ -120,6 +122,7 @@
       path = self.translate_path(self.path)
 
       if os.path.isfile(path):
+        self.send_header('Content-Encoding', 'gzip')
         etag = self.get_etag()
         if etag:
           self.send_header('ETag', etag)
@@ -136,7 +139,16 @@
 
       for prefix, local_base_path in mappings:
         if normalized_path.startswith(prefix):
-          return os.path.join(local_base_path, normalized_path[len(prefix):])
+          result = os.path.join(local_base_path, normalized_path[len(prefix):])
+          if os.path.isfile(result):
+            gz_result = result + '.gz'
+            if (not os.path.isfile(gz_result) or
+                os.path.getmtime(gz_result) <= os.path.getmtime(result)):
+              with open(result, 'rb') as f:
+                with gzip.open(gz_result, 'wb') as zf:
+                  shutil.copyfileobj(f, zf)
+            result = gz_result
+          return result
 
       # This class is only used internally, and we're adding a catch-all ''
       # prefix at the end of |mappings|.