Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(784)

Unified Diff: mojo/devtools/common/devtoolslib/http_server.py

Issue 1247573003: GZIP files served by the development server. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/devtools/common/devtoolslib/http_server.py
diff --git a/mojo/devtools/common/devtoolslib/http_server.py b/mojo/devtools/common/devtoolslib/http_server.py
index ec6973de70212a521ef54035abe4fb5c3214624a..c01928ace29b64d1e459f88ae8697e040ec4f8e1 100644
--- a/mojo/devtools/common/devtoolslib/http_server.py
+++ b/mojo/devtools/common/devtoolslib/http_server.py
@@ -6,10 +6,12 @@ import atexit
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 @@ def _GetHandlerClassForPath(mappings):
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 @@ def _GetHandlerClassForPath(mappings):
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|.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698