mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #25738: Don’t send message body for 205 Reset Content
Patch by Susumu Koshiba.
This commit is contained in:
parent
4e50553823
commit
e42e129ebe
5 changed files with 73 additions and 11 deletions
|
@ -115,6 +115,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)
|
||||
|
@ -236,6 +242,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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue