]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backporing the fix from Issue #12692
authorSenthil Kumaran <senthil@uthcode.com>
Sun, 29 Dec 2013 01:36:18 +0000 (17:36 -0800)
committerSenthil Kumaran <senthil@uthcode.com>
Sun, 29 Dec 2013 01:36:18 +0000 (17:36 -0800)
Lib/test/test_urllib2.py
Lib/urllib/request.py
Misc/NEWS

index 33f90f48ca6eb8b98e67e5353e4403dbc7fa0c1f..d4c894534a80c1541cfb9beacd8db5752f5696b8 100644 (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):
index a7445d185d0490b529f228e6ebaafeb9eb37b700..ef62acc71028c1129565b665005744b987aaef99 100644 (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
index b7924cb4bb1c9a805c7a24665ebde1c9fb872d76..b6015af966394f41ab9856651f31846b2c4bcfbc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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.