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

Unified Diff: tools/telemetry/telemetry/core/memory_cache_http_server.py

Issue 12916011: [Telemetry] Compress textual resources in memory cache http server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move str() to response time Created 7 years, 9 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: tools/telemetry/telemetry/core/memory_cache_http_server.py
diff --git a/tools/telemetry/telemetry/core/memory_cache_http_server.py b/tools/telemetry/telemetry/core/memory_cache_http_server.py
index 4efb749a1213bcac17e0a21bce1513eaf56e9613..1f10110e2e1580776603d86398574db927222b18 100644
--- a/tools/telemetry/telemetry/core/memory_cache_http_server.py
+++ b/tools/telemetry/telemetry/core/memory_cache_http_server.py
@@ -2,10 +2,12 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import BaseHTTPServer
+import mimetypes
import os
import SimpleHTTPServer
import SocketServer
import sys
+import zlib
class MemoryCacheHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
@@ -29,9 +31,11 @@ class MemoryCacheHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
resource = self.server.resource_map[path]
self.send_response(200)
self.send_header('Content-Type', ctype)
- self.send_header('Content-Length', resource['content-length'])
+ self.send_header('Content-Length', str(resource['content-length']))
self.send_header('Last-Modified',
self.date_time_string(resource['last-modified']))
+ if resource['zipped']:
+ self.send_header('Content-Encoding', 'deflate')
self.end_headers()
return resource
@@ -64,10 +68,16 @@ class MemoryCacheHTTPServer(SocketServer.ThreadingMixIn,
with open(file_path, 'rb') as fd:
response = fd.read()
fs = os.fstat(fd.fileno())
+ content_type = mimetypes.guess_type(file_path)[0]
+ zipped = False
+ if content_type and content_type.startswith('text/'):
+ zipped = True
+ response = zlib.compress(response, 9)
self.resource_map[file_path] = {
- 'content-length': str(fs[6]),
+ 'content-length': len(response),
'last-modified': fs.st_mtime,
- 'response': response
+ 'response': response,
+ 'zipped': zipped
}
« 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