# HG changeset patch # User Patrick Mezard # Date 1243182661 -7200 # Node ID e10e984bea46d1c9261b0e31c9a68e637974a31b # Parent ba42e3c6e60257e8ac86be9f4b352924fe529aae statichttprepo: handle remote not supporting Range headers - If remote does not support Range header, 200 is answered instead of 206. The HTTPRangeHandler left these responses unchanged, so the data has to be sliced by the receiver. - httprangereader file pointer was not updated. diff -r ba42e3c6e602 -r e10e984bea46 mercurial/statichttprepo.py --- a/mercurial/statichttprepo.py Sun May 24 18:30:59 2009 +0200 +++ b/mercurial/statichttprepo.py Sun May 24 18:31:01 2009 +0200 @@ -30,14 +30,31 @@ try: f = self.opener.open(req) data = f.read() + if hasattr(f, 'getcode'): + # python 2.6+ + code = f.getcode() + elif hasattr(f, 'code'): + # undocumented attribute, seems to be set in 2.4 and 2.5 + code = f.code + else: + # Don't know how to check, hope for the best. + code = 206 except urllib2.HTTPError, inst: num = inst.code == 404 and errno.ENOENT or None raise IOError(num, inst) except urllib2.URLError, inst: raise IOError(None, inst.reason[1]) - if bytes: + if code == 200: + # HTTPRangeHandler does nothing if remote does not support + # Range headers and returns the full entity. Let's slice it. + if bytes: + data = data[self.pos:self.pos + bytes] + else: + data = data[self.pos:] + elif bytes: data = data[:bytes] + self.pos += len(data) return data def build_opener(ui, authinfo):