mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Fix issue3709 - BaseHTTPRequestHandler will buffer the headers and write only on end_headers call.
This commit is contained in:
parent
a73dc9d5e8
commit
e4dad4f8e2
4 changed files with 68 additions and 9 deletions
|
@ -511,6 +511,49 @@ class BaseHTTPRequestHandlerTestCase(unittest.TestCase):
|
|||
self.verify_get_called()
|
||||
self.assertEqual(result[-1], b'<html><body>Data</body></html>\r\n')
|
||||
|
||||
def test_header_buffering(self):
|
||||
|
||||
def _readAndReseek(f):
|
||||
pos = f.tell()
|
||||
f.seek(0)
|
||||
data = f.read()
|
||||
f.seek(pos)
|
||||
return data
|
||||
|
||||
input = BytesIO(b'GET / HTTP/1.1\r\n\r\n')
|
||||
output = BytesIO()
|
||||
self.handler.rfile = input
|
||||
self.handler.wfile = output
|
||||
self.handler.request_version = 'HTTP/1.1'
|
||||
|
||||
self.handler.send_header('Foo', 'foo')
|
||||
self.handler.send_header('bar', 'bar')
|
||||
self.assertEqual(_readAndReseek(output), b'')
|
||||
self.handler.end_headers()
|
||||
self.assertEqual(_readAndReseek(output),
|
||||
b'Foo: foo\r\nbar: bar\r\n\r\n')
|
||||
|
||||
def test_header_unbuffered_when_continue(self):
|
||||
|
||||
def _readAndReseek(f):
|
||||
pos = f.tell()
|
||||
f.seek(0)
|
||||
data = f.read()
|
||||
f.seek(pos)
|
||||
return data
|
||||
|
||||
input = BytesIO(b'GET / HTTP/1.1\r\nExpect: 100-continue\r\n\r\n')
|
||||
output = BytesIO()
|
||||
self.handler.rfile = input
|
||||
self.handler.wfile = output
|
||||
self.handler.request_version = 'HTTP/1.1'
|
||||
|
||||
self.handler.handle_one_request()
|
||||
self.assertNotEqual(_readAndReseek(output), b'')
|
||||
result = _readAndReseek(output).split(b'\r\n')
|
||||
self.assertEqual(result[0], b'HTTP/1.1 100 Continue')
|
||||
self.assertEqual(result[1], b'HTTP/1.1 200 OK')
|
||||
|
||||
def test_with_continue_rejected(self):
|
||||
usual_handler = self.handler # Save to avoid breaking any subsequent tests.
|
||||
self.handler = RejectingSocketlessRequestHandler()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue