diff --git a/ceilometer/objectstore/swift_middleware.py b/ceilometer/objectstore/swift_middleware.py index c1541b8f7..9cc70ecfb 100644 --- a/ceilometer/objectstore/swift_middleware.py +++ b/ceilometer/objectstore/swift_middleware.py @@ -93,14 +93,22 @@ class CeilometerMiddleware(object): start_response_args[0] = (status, list(headers), exc_info) def iter_response(iterable): + iterator = iter(iterable) + try: + chunk = iterator.next() + while not chunk: + chunk = iterator.next() + except StopIteration: + chunk = '' + if start_response_args[0]: start_response(*start_response_args[0]) bytes_sent = 0 try: - for chunk in iterable: - if chunk: - bytes_sent += len(chunk) + while chunk: + bytes_sent += len(chunk) yield chunk + chunk = iterator.next() finally: try: self.publish_sample(env, diff --git a/ceilometer/tests/objectstore/test_swift_middleware.py b/ceilometer/tests/objectstore/test_swift_middleware.py index 64b6d931e..8ffe44e37 100644 --- a/ceilometer/tests/objectstore/test_swift_middleware.py +++ b/ceilometer/tests/objectstore/test_swift_middleware.py @@ -39,13 +39,15 @@ class FakeApp(object): self.body = body def __call__(self, env, start_response): + yield start_response('200 OK', [ ('Content-Type', 'text/plain'), ('Content-Length', str(sum(map(len, self.body)))) ]) while env['wsgi.input'].read(5): pass - return self.body + for line in self.body: + yield line class TestSwiftMiddleware(tests_base.BaseTestCase):