[PATCH] don't send Range header when requesting entire file

Alexander Boyd alex at opengroove.org
Sat Jun 9 20:29:10 CDT 2012


# HG changeset patch
# User Alexander Boyd <alex at opengroove.org>
# Date 1339290804 21600
# Node ID db8c16eabe206dcc18e2450d2cdb0b28ac9c9f22
# Parent  5af80d29c4411d2bb58cb4356851f0543376dcec
don't send Range header when requesting entire file

When requesting files using statichttprepo.httprangereader, a request for the
entire file is sent with a Range: bytes=0- header. This causes problems with
web servers such as Cherokee that return an HTTP 416 when an empty file is
requested in this way, which in turn cause some repository clone attempts to
fail. This patch omits the Range header when the entire file is being
requested, which fixes the problem.

diff -r 5af80d29c441 -r db8c16eabe20 mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py	Sat Jun 09 14:20:25 2012 +0200
+++ b/mercurial/statichttprepo.py	Sat Jun 09 19:13:24 2012 -0600
@@ -26,7 +26,8 @@
         end = ''
         if bytes:
             end = self.pos + bytes - 1
-        req.add_header('Range', 'bytes=%d-%s' % (self.pos, end))
+        if self.pos or end:
+            req.add_header('Range', 'bytes=%d-%s' % (self.pos, end))
 
         try:
             f = self.opener.open(req)


More information about the Mercurial-devel mailing list