# HG changeset patch
# User Alexis S. L. Carvalho <alexis@cecm.usp.br>
# Date 2006-04-30 16:50:53
# Node ID 12e11413ca19b9e93e84435c915a34fcf7f73bae
# Parent  858df1f354c11def7c699b7eee4f52dcb85656c5

Fix just introduced possible old-http bug

My last patch changed httprangereader.read to read only the specified
amount of data from the connection, to prevent it from returning more
than what was asked.

I just realized that this could lead to the connection not being closed.
In practice, it looks like the connection is closed just fine, but it's
probably safer to read everything and then return only what's necessary.



diff --git a/mercurial/httprangereader.py b/mercurial/httprangereader.py
--- a/mercurial/httprangereader.py
+++ b/mercurial/httprangereader.py
@@ -22,4 +22,7 @@ class httprangereader(object):
             end = self.pos + bytes - 1
         req.add_header('Range', 'bytes=%d-%s' % (self.pos, end))
         f = urllib2.urlopen(req)
-        return f.read(bytes)
+        data = f.read()
+        if bytes:
+            data = data[:bytes]
+        return data