[PATCH] Fix gzip tarball annoyances with gzip capable proxies [Was Re: Hourly snapshots are not up to date]

Vincent Wagelaar vincent at ricardis.tudelft.nl
Wed Aug 31 08:11:58 CDT 2005


On Wednesday 31 August 2005 14:35, Edouard Gomez wrote:
> Thomas Arendsen Hein <thomas <at> intevation.de> writes:
> > Why not? This just doesn't include the .hg directory that Matt's
> > hourly snapshots do.
>
> True.
>
> > > Looking at the file content show two things:
> > >  - the contents are truncated
> > >  - the contents are not gzipped, but they are tar'ed
> >
> > This must be a local problem on your side.
>
> Using too fancy editors like emacs and vim can lead to false problems
> because of autoinflating... both symptoms are wrong problems.
>
> This made me think that Apache2 was maybe thinking the content was gzip
> encoded, so i ended hinting it including a content-encoding header and
> changing the content type to x-tar (which means it's compressed).
> The proxy did not to bork the gziped file anymore.
>
> I'm not very happy using req.write directly, isn't there a better way to
> send custom headers ? If no, then please apply the following patch.
>
> # HG changeset patch
> # User Edouard Gomez <ed.gomez at free.fr>
> # Node ID e819632d34d33d0abf5b456c6b0a077999664fc6
> # Parent  9d9f4973c76ad99a1e977eecc652559e12f53aef
> Fix gzip tarball annoyances with gzip capable proxies
>
> It seems gzip capable proxies deal poorly with generated
> gzip tarballs. Including a Content-Encoding header fixes
> the problem.
>
> diff -r 9d9f4973c76a -r e819632d34d3 mercurial/hgweb.py
> --- a/mercurial/hgweb.py	Wed Aug 31 07:01:41 2005
> +++ b/mercurial/hgweb.py	Wed Aug 31 12:22:03 2005
> @@ -689,7 +689,12 @@
>              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.write('Content-encoding: %s\r\n' % encoding)
> +            req.httphdr('application/x-tar', name[:-1] + '.tar.' + type)
>              for fname in files:
>                  rcont = self.repo.file(fname).read(mf[fname])
>                  finfo = tarfile.TarInfo(name + fname)
req.header([('Content-type', 'application/x-tar'), 
   ('Content-disposition', 'attachment; filename=%s%s' % (name[:-1], 
'.tar.')),
  ('Content-encoding', encoding)])

Sorry for the formatting

Cheers,
Vincent


More information about the Mercurial mailing list