]> granicus.if.org Git - python/commitdiff
Closes issue11563 - test_urllibnet ResourceWarning. Patch by Jeff McNeil.
authorSenthil Kumaran <orsenthil@gmail.com>
Sat, 19 Mar 2011 09:25:27 +0000 (17:25 +0800)
committerSenthil Kumaran <orsenthil@gmail.com>
Sat, 19 Mar 2011 09:25:27 +0000 (17:25 +0800)
Lib/test/test_urllib.py
Lib/urllib/request.py

index 673afc42a69a55996e8ac0988ccebc54ec600fee..074d833ca47459d8855cda3b9e26b77d8a9c2bc9 100644 (file)
@@ -91,7 +91,7 @@ class urlopen_FileTests(unittest.TestCase):
                          "did not return the expected text")
 
     def test_close(self):
-        # Test close() by calling it hear and then having it be called again
+        # Test close() by calling it here and then having it be called again
         # by the tearDown() method for the test
         self.returned_obj.close()
 
@@ -174,6 +174,11 @@ class urlopen_HttpTests(unittest.TestCase):
         finally:
             self.unfakehttp()
 
+    def test_willclose(self):
+        self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello!")
+        resp = urlopen("http://www.python.org")
+        self.assertTrue(resp.fp.will_close)
+
     def test_read_0_9(self):
         # "0.9" response accepted (but not "simple responses" without
         # a status line)
index 1e437b5b866b4a1acc65ffada7f06563dca072be..4d3648d0f2c35eb4563dd060b14377b4ef8f1f91 100644 (file)
@@ -1657,6 +1657,12 @@ class URLopener:
             headers["Authorization"] =  "Basic %s" % auth
         if realhost:
             headers["Host"] = realhost
+
+        # Add Connection:close as we don't support persistent connections yet.
+        # This helps in closing the socket and avoiding ResourceWarning
+
+        headers["Connection"] = "close"
+
         for header, value in self.addheaders:
             headers[header] = value