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

Laurens Holst laurens.nospam at grauw.nl
Wed Oct 6 06:51:28 CDT 2010


  Hi,

I’ve also had issues with search robots pulling down the .gz and 
.bz2-files (not the .zip) in their entirety, leading me to disable these 
formats in hgweb as it was causing issues wrt. monthly bandwidth 
limitations. Hopefully sending these more correct MIME-types will also 
improve that situation.

~Laurens

Op 20-9-2010 23:41, Ry4an Brase schreef:
> # 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),
>           }
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>


-- 
~~ Ushiko-san! Kimi wa doushite, Ushiko-san nan da!! ~~
Laurens Holst, developer, Utrecht, the Netherlands
Website: www.grauw.nl. Backbase employee; www.backbase.com


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5278 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20101006/bd3ce363/attachment.bin>


More information about the Mercurial-devel mailing list