summaryrefslogtreecommitdiff
path: root/Lib/test/test_httplib.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2009-03-28 04:34:21 +0000
committerJeremy Hylton <jeremy@alum.mit.edu>2009-03-28 04:34:21 +0000
commit636950f925d50763537d40342ec622808c9b7e9d (patch)
treeffd2880a6d118f374af24da66f435c6027eddca8 /Lib/test/test_httplib.py
parent7c1692d587b62bbb0657d6c049e320e37c53e711 (diff)
downloadcpython-git-636950f925d50763537d40342ec622808c9b7e9d.tar.gz
Remove special logic that closes HTTPConnection socket on EPIPE.
http://bugs.python.org/issue5542 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. Also, various formatting changes.
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r--Lib/test/test_httplib.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 89413a5e0c..d43c82d40f 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -1,3 +1,4 @@
+import errno
from http import client
import io
import socket
@@ -24,6 +25,21 @@ class FakeSocket:
raise client.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(io.BytesIO):
"""Like StringIO, but raises AssertionError on EOF.
@@ -213,6 +229,20 @@ 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 = client.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):
@@ -277,7 +307,7 @@ class RequestBodyTest(TestCase):
def setUp(self):
self.conn = client.HTTPConnection('example.com')
- self.sock = FakeSocket("")
+ self.conn.sock = self.sock = FakeSocket("")
self.conn.sock = self.sock
def get_headers_and_fp(self):