From f70feb39b99202e6f4283c30c5b3548f6ba918ce Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Mon, 11 Sep 2017 15:21:22 +0000 Subject: [PATCH] swob: Raise RuntimeError instead of IndexError ... when the underlying application forgets to call start_response. Change-Id: I092be4bfdf5b1d7819fc1540307eaa918970e5b6 Closes-Bug: 1462226 --- swift/common/swob.py | 2 ++ test/unit/common/test_swob.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) 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