]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
merge from 3.2 - fix urlopen behavior on sites which do not send (or obsfuscates...
authorSenthil Kumaran <senthil@uthcode.com>
Wed, 27 Jul 2011 01:37:17 +0000 (09:37 +0800)
committerSenthil Kumaran <senthil@uthcode.com>
Wed, 27 Jul 2011 01:37:17 +0000 (09:37 +0800)
Lib/test/test_urllib2net.py
Lib/urllib2.py

index 5ffba87fdfc8ca6ad5eb859c5460e3e2efb18067..1375cdada0084f0aefe7d7f0556ac57c08e7e0d8 100644 (file)
@@ -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
index 2bce745e6372f52a8c977d5554bc4841b9f69a94..a0065b5b84df9f4c42dce3dd0eac91556b5044f0 100644 (file)
@@ -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.