swob: Raise RuntimeError instead of IndexError

... when the underlying application forgets to call start_response.

Change-Id: I092be4bfdf5b1d7819fc1540307eaa918970e5b6
Closes-Bug: 1462226
This commit is contained in:
Tim Burke 2017-09-11 15:21:22 +00:00
parent 834b733d29
commit f70feb39b9
2 changed files with 26 additions and 0 deletions

View File

@ -999,6 +999,8 @@ class Request(object):
app_iter = output
if not captured:
app_iter = reiterate(app_iter)
if not captured:
raise RuntimeError('application never called start_response')
return (captured[0], captured[1], app_iter)
def get_response(self, application):

View File

@ -1079,6 +1079,30 @@ class TestResponse(unittest.TestCase):
app_iter.close()
self.assertRaises(StopIteration, iterator.next)
def test_call_finds_nonempty_chunk(self):
def test_app(environ, start_response):
start_response('400 Bad Request', [])
yield ''
start_response('200 OK', [])
yield 'complete '
yield ''
yield 'response'
req = swift.common.swob.Request.blank('/')
req.method = 'GET'
status, headers, app_iter = req.call_application(test_app)
self.assertEqual(status, '200 OK')
self.assertEqual(list(app_iter), ['complete ', '', 'response'])
def test_call_requires_that_start_response_is_called(self):
def test_app(environ, start_response):
yield 'response'
req = swift.common.swob.Request.blank('/')
req.method = 'GET'
with self.assertRaises(RuntimeError) as mgr:
req.call_application(test_app)
self.assertEqual(mgr.exception.args[0],
'application never called start_response')
def test_location_rewrite(self):
def start_response(env, headers):
pass