]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Bug #767111: fix long-standing bug in urllib which caused an
authorGeorg Brandl <georg@python.org>
Wed, 14 Mar 2007 08:27:57 +0000 (08:27 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 14 Mar 2007 08:27:57 +0000 (08:27 +0000)
AttributeError instead of an IOError when the server's response didn't
contain a valid HTTP status line.
 (backport from rev. 54376)

Lib/test/test_urllib.py
Lib/urllib.py
Misc/NEWS

index 4579c479d1478bbf06425104ee2f74531499514b..294ed5e06a203a3d13669a186069b6a343742596 100644 (file)
@@ -122,6 +122,15 @@ class urlopen_HttpTests(unittest.TestCase):
         finally:
             self.unfakehttp()
 
+    def test_empty_socket(self):
+        """urlopen() raises IOError if the underlying socket does not send any
+        data. (#1680230) """
+        self.fakehttp('')
+        try:
+            self.assertRaises(IOError, urllib.urlopen, 'http://something')
+        finally:
+            self.unfakehttp()
+
 class urlretrieve_FileTests(unittest.TestCase):
     """Test urllib.urlretrieve() on local files"""
 
index 9fbb19a4198f703dd612bcc5f885f9b161e3ab52..963187cfb27dc58887e0f3b7355c4cc4e6a995e8 100644 (file)
@@ -326,6 +326,10 @@ class URLopener:
         if data is not None:
             h.send(data)
         errcode, errmsg, headers = h.getreply()
+        if errcode == -1:
+            # something went wrong with the HTTP status line
+            raise IOError, ('http protocol error', 0,
+                            'got a bad status line', None)
         fp = h.getfile()
         if errcode == 200:
             return addinfourl(fp, headers, "http:" + url)
@@ -413,6 +417,10 @@ class URLopener:
             if data is not None:
                 h.send(data)
             errcode, errmsg, headers = h.getreply()
+            if errcode == -1:
+                # something went wrong with the HTTP status line
+                raise IOError, ('http protocol error', 0,
+                                'got a bad status line', None)
             fp = h.getfile()
             if errcode == 200:
                 return addinfourl(fp, headers, "https:" + url)
index d94b0f79accc8f7badddd71a7c34d2146e0c1a4b..379899444e26451490c4c2374c6c688bcd047bc8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -205,6 +205,10 @@ Extension Modules
 Library
 -------
 
+- Bug #767111: fix long-standing bug in urllib which caused an
+  AttributeError instead of an IOError when the server's response didn't
+  contain a valid HTTP status line.
+
 - Patch #1449244: Support Unicode strings in
   email.message.Message.{set_charset,get_content_charset}.