summaryrefslogtreecommitdiff
path: root/Lib/test/test_httplib.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-07-24 02:46:16 +0000
committerVictor Stinner <victor.stinner@haypocalc.com>2010-07-24 02:46:16 +0000
commit2c6aee9096c7502ad2ec1c522f4b0e9be0a6569d (patch)
tree3d61a5890a8c5a8528079fe5f5cf625fd344e740 /Lib/test/test_httplib.py
parent4c16d122c42494ac735d5417cd79c70d67d341e0 (diff)
downloadcpython-git-2c6aee9096c7502ad2ec1c522f4b0e9be0a6569d.tar.gz
Forward port r70643 (#5542) + part of r83120 (just remove the comment)
Remove special logic that closes HTTPConnection socket on EPIPE. If the socket is closed, the client has no chance to read the response from the server. EPIPE means that it isn't possible to write more data from the socket, but not that it is impossible to read.
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r--Lib/test/test_httplib.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 2d0b8e750b..1fb810e816 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -2,6 +2,7 @@ import array
import httplib
import StringIO
import socket
+import errno
import unittest
TestCase = unittest.TestCase
@@ -24,6 +25,21 @@ class FakeSocket:
raise httplib.UnimplementedFileMode()
return self.fileclass(self.text)
+class EPipeSocket(FakeSocket):
+
+ def __init__(self, text, pipe_trigger):
+ # When sendall() is called with pipe_trigger, raise EPIPE.
+ FakeSocket.__init__(self, text)
+ self.pipe_trigger = pipe_trigger
+
+ def sendall(self, data):
+ if self.pipe_trigger in data:
+ raise socket.error(errno.EPIPE, "gotcha")
+ self.data += data
+
+ def close(self):
+ pass
+
class NoEOFStringIO(StringIO.StringIO):
"""Like StringIO, but raises AssertionError on EOF.
@@ -254,6 +270,21 @@ class BasicTest(TestCase):
finally:
resp.close()
+ def test_epipe(self):
+ sock = EPipeSocket(
+ "HTTP/1.0 401 Authorization Required\r\n"
+ "Content-type: text/html\r\n"
+ "WWW-Authenticate: Basic realm=\"example\"\r\n",
+ b"Content-Length")
+ conn = httplib.HTTPConnection("example.com")
+ conn.sock = sock
+ self.assertRaises(socket.error,
+ lambda: conn.request("PUT", "/url", "body"))
+ resp = conn.getresponse()
+ self.assertEqual(401, resp.status)
+ self.assertEqual("Basic realm=\"example\"",
+ resp.getheader("www-authenticate"))
+
class OfflineTest(TestCase):
def test_responses(self):