diff --git a/swift/common/swob.py b/swift/common/swob.py index dc96b8d7a1..eb585a2846 100644 --- a/swift/common/swob.py +++ b/swift/common/swob.py @@ -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): diff --git a/test/unit/common/test_swob.py b/test/unit/common/test_swob.py index a5426f7bf9..b2ee485eea 100644 --- a/test/unit/common/test_swob.py +++ b/test/unit/common/test_swob.py @@ -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