[PATCH] Correct Content-Type header values for archive downloads

Ry4an Brase ry4an-hg at ry4an.org
Mon Sep 20 16:41:03 CDT 2010

# HG changeset patch
# User Ry4an Brase <ry4an-hg at ry4an.org>
# Date 1285012568 18000
# Node ID ee5cbed86833252ff9dabe34ba21c59b28207dc0
# Parent  e0ee3e822a9acb8d14602abdaa76740734977f2c
Correct Content-Type header values for archive downloads.

The content type for both .tar.gz and .tar.bz2 downloads was
application/x-tar, which is correct for .tar files when no
Content-Encoding is present, but is not correct for .tar.gz and .tar.bz2
files unless Content-Encoding is set to gzip or x-bzip2, respectively.

However, setting Content-Encoding causes browsers to undo that encoding
during download, when a .gz or .bz2 file is usually the desired
artifact.  Omitting the Content-Encoding header is preferred to avoid
having browsers uncompress non-render-able files.

Additionally, the Content-Disposition line indicates a final desired
filename with .tar.gz or .tar.bz2 extension which makes providing a
Content-Encoding header inappropriate.

With the current configuration browsers (Chrome and Firefox thus far)
are registering the application/x-tar Content-Type and not .tar
extension and appending that extension, yielding filename.tar.gz.tar as
a final on-disk artifact.

I've changed the .tar.gz and .tar.bz2 Content-Types to
application/x-gzip and application/octet-stream, restively.  Which
yields correctly named download artifacts.

diff -r e0ee3e822a9a -r ee5cbed86833 mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py	Mon Sep 20 22:29:13 2010 +0200
+++ b/mercurial/hgweb/hgweb_mod.py	Mon Sep 20 14:56:08 2010 -0500
@@ -276,8 +276,8 @@
                 yield {"type" : i, "extension" : spec[2], "node" : nodeid}
     archive_specs = {
-        'bz2': ('application/x-tar', 'tbz2', '.tar.bz2', None),
-        'gz': ('application/x-tar', 'tgz', '.tar.gz', None),
+        'bz2': ('application/octet-stream', 'tbz2', '.tar.bz2', None),
+        'gz': ('application/x-gzip', 'tgz', '.tar.gz', None),
         'zip': ('application/zip', 'zip', '.zip', None),

More information about the Mercurial-devel mailing list