summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_httpservers.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-06-08 09:45:58 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-06-08 09:45:58 (GMT)
commit40de69ac588cece85fd3ed7fad06cdfdaf8f5e6a (patch)
tree050a0298638d1ccc2d272c8590a5277a12cd7bd1 /Lib/test/test_httpservers.py
parent58f016909e7feead26d9c6e772a96a66b6e9f970 (diff)
parente42e129ebec9918adcae6f93b18bb6652f29c3fe (diff)
downloadcpython-40de69ac588cece85fd3ed7fad06cdfdaf8f5e6a.zip
cpython-40de69ac588cece85fd3ed7fad06cdfdaf8f5e6a.tar.gz
cpython-40de69ac588cece85fd3ed7fad06cdfdaf8f5e6a.tar.bz2
Issue #25738: Merge HTTP server from 3.5
Diffstat (limited to 'Lib/test/test_httpservers.py')
-rw-r--r--Lib/test/test_httpservers.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index 9b96a29..7f4b0f9 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -116,6 +116,12 @@ class BaseHTTPServerTestCase(BaseTestCase):
body = self.headers['x-special-incoming'].encode('utf-8')
self.wfile.write(body)
+ def do_SEND_ERROR(self):
+ self.send_error(int(self.path[1:]))
+
+ def do_HEAD(self):
+ self.send_error(int(self.path[1:]))
+
def setUp(self):
BaseTestCase.setUp(self)
self.con = http.client.HTTPConnection(self.HOST, self.PORT)
@@ -237,6 +243,44 @@ class BaseHTTPServerTestCase(BaseTestCase):
data = res.read()
self.assertEqual(int(res.getheader('Content-Length')), len(data))
+ def test_send_error(self):
+ allow_transfer_encoding_codes = (HTTPStatus.NOT_MODIFIED,
+ HTTPStatus.RESET_CONTENT)
+ for code in (HTTPStatus.NO_CONTENT, HTTPStatus.NOT_MODIFIED,
+ HTTPStatus.PROCESSING, HTTPStatus.RESET_CONTENT,
+ HTTPStatus.SWITCHING_PROTOCOLS):
+ self.con.request('SEND_ERROR', '/{}'.format(code))
+ res = self.con.getresponse()
+ self.assertEqual(code, res.status)
+ self.assertEqual(None, res.getheader('Content-Length'))
+ self.assertEqual(None, res.getheader('Content-Type'))
+ if code not in allow_transfer_encoding_codes:
+ self.assertEqual(None, res.getheader('Transfer-Encoding'))
+
+ data = res.read()
+ self.assertEqual(b'', data)
+
+ def test_head_via_send_error(self):
+ allow_transfer_encoding_codes = (HTTPStatus.NOT_MODIFIED,
+ HTTPStatus.RESET_CONTENT)
+ for code in (HTTPStatus.OK, HTTPStatus.NO_CONTENT,
+ HTTPStatus.NOT_MODIFIED, HTTPStatus.RESET_CONTENT,
+ HTTPStatus.SWITCHING_PROTOCOLS):
+ self.con.request('HEAD', '/{}'.format(code))
+ res = self.con.getresponse()
+ self.assertEqual(code, res.status)
+ if code == HTTPStatus.OK:
+ self.assertTrue(int(res.getheader('Content-Length')) > 0)
+ self.assertIn('text/html', res.getheader('Content-Type'))
+ else:
+ self.assertEqual(None, res.getheader('Content-Length'))
+ self.assertEqual(None, res.getheader('Content-Type'))
+ if code not in allow_transfer_encoding_codes:
+ self.assertEqual(None, res.getheader('Transfer-Encoding'))
+
+ data = res.read()
+ self.assertEqual(b'', data)
+
class RequestHandlerLoggingTestCase(BaseTestCase):
class request_handler(BaseHTTPRequestHandler):