Author martin.panter
Recipients SilentGhost, kristjan.jonsson, martin.panter, maubp, serhiy.storchaka
Date 2016-03-09.07:29:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1457508587.81.0.32623148343.issue26499@psf.upfronthosting.co.za>
In-reply-to
Content
Thanks for the report and the patch. It looks okay as far as it goes, but I think there are other related bugs:

## read1() doesn’t update length either ##

>>> handle = urlopen("https://www.python.org/")
>>> len(handle.read1())
7374
>>> handle.read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/proj/python/cpython/Lib/http/client.py", line 462, in read
    s = self._safe_read(self.length)
  File "/home/proj/python/cpython/Lib/http/client.py", line 614, in _safe_read
    raise IncompleteRead(b''.join(s), amt)
http.client.IncompleteRead: IncompleteRead(39583 bytes read, 7374 more expected)

## readline() and read1() blindly read beyond Content-Length ##

>>> conn = HTTPSConnection("www.python.org")
>>> conn.request("GET", "/")
>>> resp = conn.getresponse()
>>> resp.readlines()  # Hangs until the connection is closed

I wonder if anyone has considered implementing HTTPResponse by wrapping or subclassing BufferedReader; that way you get well-tested readline() etc functionality for free. The HTTP protocol (Connection: close, Content-Length, chunked decoding) could be handled by an internal RawIOBase.readinto() method.
History
Date User Action Args
2016-03-09 07:29:47martin.pantersetrecipients: + martin.panter, kristjan.jonsson, SilentGhost, maubp, serhiy.storchaka
2016-03-09 07:29:47martin.pantersetmessageid: <1457508587.81.0.32623148343.issue26499@psf.upfronthosting.co.za>
2016-03-09 07:29:47martin.panterlinkissue26499 messages
2016-03-09 07:29:46martin.pantercreate