diff -r 1cb486f4e18d Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py Thu Mar 17 11:04:34 2011 -0400 +++ b/Lib/test/test_urllib.py Thu Mar 17 14:23:37 2011 -0400 @@ -91,7 +91,7 @@ "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 @@ 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) diff -r 1cb486f4e18d Lib/urllib/request.py --- a/Lib/urllib/request.py Thu Mar 17 11:04:34 2011 -0400 +++ b/Lib/urllib/request.py Thu Mar 17 14:23:37 2011 -0400 @@ -1650,7 +1650,12 @@ else: auth = None http_conn = connection_factory(host) - headers = {} + + # Force decouple of HTTPConnection & HTTPResponse as we're not + # interested in Keep Alive. The response object should own + # the close action. + headers = {'Connection': 'close'} + if proxy_auth: headers["Proxy-Authorization"] = "Basic %s" % proxy_auth if auth: