summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_httpservers.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-06-08 07:16:14 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-06-08 07:16:14 (GMT)
commit6af1c49bb497ca883af99db19aaaae8820325f90 (patch)
treed98b9c263bb0f1dc0df3b73221cf2acc56021258 /Lib/test/test_httpservers.py
parentc36364491fb5bedc736957ce123f30d8a7b7023c (diff)
downloadcpython-6af1c49bb497ca883af99db19aaaae8820325f90.zip
cpython-6af1c49bb497ca883af99db19aaaae8820325f90.tar.gz
cpython-6af1c49bb497ca883af99db19aaaae8820325f90.tar.bz2
Issue #25738: Don’t send message body for 205 Reset Content
Patch by Susumu Koshiba.
Diffstat (limited to 'Lib/test/test_httpservers.py')
-rw-r--r--Lib/test/test_httpservers.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index 672c187..1b6339d 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -178,6 +178,12 @@ class BaseHTTPServerTestCase(BaseTestCase):
self.send_header('Connection', 'close')
self.end_headers()
+ 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 = httplib.HTTPConnection('localhost', self.PORT)
@@ -276,6 +282,38 @@ class BaseHTTPServerTestCase(BaseTestCase):
res = self.con.getresponse()
self.assertEqual(res.status, 999)
+ def test_send_error(self):
+ allow_transfer_encoding_codes = (205, 304)
+ for code in (101, 102, 204, 205, 304):
+ 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 = (205, 304)
+ for code in (101, 200, 204, 205, 304):
+ self.con.request('HEAD', '/{}'.format(code))
+ res = self.con.getresponse()
+ self.assertEqual(code, res.status)
+ if code == 200:
+ self.assertEqual(None, res.getheader('Content-Length'))
+ 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 SimpleHTTPServerTestCase(BaseTestCase):
class request_handler(NoLogRequestHandler, SimpleHTTPRequestHandler):