Backporing the fix from Issue #12692

This commit is contained in:
Senthil Kumaran 2013-12-28 17:36:18 -08:00
parent 3e86ba4e32
commit b6fac245b5
3 changed files with 10 additions and 0 deletions

View File

@ -283,6 +283,7 @@ class MockHTTPClass:
self.req_headers = []
self.data = None
self.raise_on_endheaders = False
self.sock = None
self._tunnel_headers = {}
def __call__(self, host, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):

View File

@ -1251,6 +1251,12 @@ class AbstractHTTPHandler(BaseHandler):
raise URLError(err)
else:
r = h.getresponse()
# If the server does not send us a 'Connection: close' header,
# HTTPConnection assumes the socket should be left open. Manually
# mark the socket to be closed when this response object goes away.
if h.sock:
h.sock.close()
h.sock = None
r.url = req.get_full_url()
# This line replaces the .msg attribute of the HTTPResponse

View File

@ -29,6 +29,9 @@ Core and Builtins
Library
-------
- Issue #12692: Backport the fix for ResourceWarning in test_urllib2net. This
also helps in closing the socket when Connection Close header is not sent.
- Issue #19422: Explicitly disallow non-SOCK_STREAM sockets in the ssl
module, rather than silently let them emit clear text data.