Iterates swift response earlier to get the correct status

We must iterate the next middleware app until we get a response
before asking for the headers and status.

Closes-bug: #1326250

Change-Id: I8947bc88754db93e3ebe01ea864c4b489d1bd870
This commit is contained in:
Mehdi Abaakouk 2014-06-03 18:46:06 +02:00
parent 6b85ba46c8
commit 163710cb1a
2 changed files with 14 additions and 4 deletions

View File

@ -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:
while chunk:
bytes_sent += len(chunk)
yield chunk
chunk = iterator.next()
finally:
try:
self.publish_sample(env,

View File

@ -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):