[New-bugs-announce] [issue7806] httplib.HTTPConnection.getresponse closes socket which destroys the response

Robert Buchholz report at bugs.python.org
Fri Jan 29 16:01:51 CET 2010


New submission from Robert Buchholz <rbu at freitagsrunde.org>:

Calling getresponse() on an httplib.HTTPConnection object returns a response object. Internally, the self.sock is handed over to the HTTPResponse object which transforms it into a file-like object. The response object is returned to the caller. If one calls response.read() later on, no or incomplete content will be returned because the underlying socket has been closed.

The code path, simplified:

class HTTPConnection:

    def getresponse(self):
            response = self.response_class(self.sock, ...)
            ...
            if response.will_close:
                # this effectively passes the connection to the response
                self.close()

    def close(self):
        if self.sock:
            self.sock.close()
        ...

class HTTPResponse:
    def __init__(self, sock, debuglevel=0, strict=0, method=None):
        self.fp = sock.makefile('rb', 0)
        ...

----------
components: Library (Lib)
messages: 98513
nosy: Robert.Buchholz
severity: normal
status: open
title: httplib.HTTPConnection.getresponse closes socket which destroys the response
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7806>
_______________________________________


More information about the New-bugs-announce mailing list