[PATCH] Output Content-encoding for tar.gz and tar.bz2 snapshots

Edouard Gomez ed.gomez at free.fr
Thu Sep 1 02:52:08 CDT 2005


I got rid of the nasty req.write thanks to Vincent Wagelaar's advise.
So here is a new try at fixing the tar.gz|bz2 handling with some gz capable
proxies.

The patch is against the 'crew' branch.

# HG changeset patch
# User Edouard Gomez <ed.gomez at free.fr>
# Node ID 04d53c052d3925c86900cda08304f47a5c44ae98
# Parent  9d9f4973c76ad99a1e977eecc652559e12f53aef
Output Content-encoding for tar.gz and tar.bz2 snapshots

If the HTTP header 'Content-encoding' is missing for tar.gz
snapshots, some gzip capable proxies can bork the tarball and
serve unusable files to users.

GZ tarballs are served using Content-encoding: gzip.
BZ2 tarballs are served using Content-encoding: x-bzip2.

diff -r 9d9f4973c76a -r 04d53c052d39 mercurial/hgweb.py
--- a/mercurial/hgweb.py	Wed Aug 31 07:01:41 2005
+++ b/mercurial/hgweb.py	Thu Sep  1 07:47:34 2005
@@ -689,7 +689,14 @@
             mff = self.repo.manifest.readflags(mnode)
             mtime = int(time.time())
 
-            req.httphdr('application/octet-stream', name[:-1] + '.tar.' + type)
+            if type == "gz":
+                encoding = "gzip"
+            else:
+                encoding = "x-bzip2"
+            req.header([('Content-type', 'application/x-tar'), 
+                    ('Content-disposition', 'attachment; filename=%s%s%s' %
+                        (name[:-1], '.tar.', type)),
+                    ('Content-encoding', encoding)])
             for fname in files:
                 rcont = self.repo.file(fname).read(mf[fname])
                 finfo = tarfile.TarInfo(name + fname)




More information about the Mercurial mailing list