diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 6f13999aa3..8a892a67e3 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -249,10 +249,6 @@ class WSGIContext(object): """ def __init__(self, wsgi_app): self.app = wsgi_app - # Results from the last call to self._start_response. - self._response_status = None - self._response_headers = None - self._response_exc_info = None def _start_response(self, status, headers, exc_info=None): """ @@ -267,6 +263,9 @@ class WSGIContext(object): """ Ensures start_response has been called before returning. """ + self._response_status = None + self._response_headers = None + self._response_exc_info = None resp = self.app(env, self._start_response) # if start_response has been called, just return the iter if self._response_status is not None: diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index 4884104371..aee62556a7 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -238,5 +238,25 @@ class TestWSGI(unittest.TestCase): self.assertEquals(e['PATH_INFO'], '/override') +class TestWSGIContext(unittest.TestCase): + + def test_app_call(self): + statuses = ['200 Ok', '404 Not Found'] + + def app(env, start_response): + start_response(statuses.pop(0), [('Content-Length', '3')]) + yield 'Ok\n' + + wc = wsgi.WSGIContext(app) + r = Request.blank('/') + it = wc._app_call(r.environ) + self.assertEquals(wc._response_status, '200 Ok') + self.assertEquals(''.join(it), 'Ok\n') + r = Request.blank('/') + it = wc._app_call(r.environ) + self.assertEquals(wc._response_status, '404 Not Found') + self.assertEquals(''.join(it), 'Ok\n') + + if __name__ == '__main__': unittest.main()