diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2011-07-27 01:37:17 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2011-07-27 01:37:17 (GMT) |
commit | 7d7702b5819f2ef262353055f265c7d8d1f39823 (patch) | |
tree | 303809f1c5ebfc56e7a3476b543628a5987f6c95 | |
parent | d8b1723965ba05d579525c9f09a79d58c18b4a84 (diff) | |
download | cpython-7d7702b5819f2ef262353055f265c7d8d1f39823.zip cpython-7d7702b5819f2ef262353055f265c7d8d1f39823.tar.gz cpython-7d7702b5819f2ef262353055f265c7d8d1f39823.tar.bz2 |
merge from 3.2 - fix urlopen behavior on sites which do not send (or obsfuscates) Connection: Close header.
-rw-r--r-- | Lib/test/test_urllib2net.py | 8 | ||||
-rw-r--r-- | Lib/urllib2.py | 10 |
2 files changed, 13 insertions, 5 deletions
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index 5ffba87..1375cda 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -186,6 +186,14 @@ class OtherNetworkTests(unittest.TestCase): opener.open(request) self.assertEqual(request.get_header('User-agent'),'Test-Agent') + def test_sites_no_connection_close(self): + # Some sites do not send Connection: close header. + # Verify that those work properly. (#issue12576) + + req = urllib2.urlopen('http://www.imdb.com') + res = req.read() + self.assertTrue(res) + def _test_urls(self, urls, handlers, retry=True): import time import logging diff --git a/Lib/urllib2.py b/Lib/urllib2.py index 2bce745..a0065b5 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -1166,14 +1166,14 @@ class AbstractHTTPHandler(BaseHandler): try: h.request(req.get_method(), req.get_selector(), req.data, headers) + except socket.error, err: # XXX what error? + h.close() + raise URLError(err) + else: try: r = h.getresponse(buffering=True) - except TypeError: #buffering kw not supported + except TypeError: # buffering kw not supported r = h.getresponse() - except socket.error, err: # XXX what error? - raise URLError(err) - finally: - h.close() # Pick apart the HTTPResponse object to get the addinfourl # object initialized properly. |