Do not use the gzipped file to compute the ETag. gzip is not a stable format. If the file didn't change but the gz doesn't exist, the etag would change which would force the shell to re-download the content. R=ppi@chromium.org Review URL: https://codereview.chromium.org/1263093004 . Cr-Mirrored-From: https://github.com/domokit/mojo Cr-Mirrored-Commit: 65ca02044f3969b24640963f57e094210ccfaa84
diff --git a/devtoolslib/http_server.py b/devtoolslib/http_server.py index 5199f3e..67bb402 100644 --- a/devtoolslib/http_server.py +++ b/devtoolslib/http_server.py
@@ -74,7 +74,7 @@ if self.etag: return self.etag - path = self.translate_path(self.path) + path = self.translate_path(self.path, False) if not os.path.isfile(path): return None @@ -130,7 +130,8 @@ return SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self) - def translate_path(self, path): + # pylint: disable=W0221 + def translate_path(self, path, gzipped=True): # Parent translate_path() will strip away the query string and fragment # identifier, but also will prepend the cwd to the path. relpath() gives # us the relative path back. @@ -141,13 +142,14 @@ if normalized_path.startswith(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 + if gzipped: + 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 ''