Skip to content

Commit

Permalink
Make proxy-logging more like eventlet.posthook
Browse files Browse the repository at this point in the history
The old use of Eventlet's posthook process meant that responses that
forgot to include content-length or transfer-encoding headers would
get one tacked on, if Eventlet could guess what was probably meant. I
added a bit of that logic into proxy-logging now as we saw some
errors resulting from this.

Fixes Bug #1012714

Change-Id: I671453eaf3704eab814ff12c4625ba7d749cc7ed
  • Loading branch information
gholt committed Jun 13, 2012
1 parent 95786e5 commit 8b778c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions swift/common/middleware/proxy_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def iter_response(iterable):
else:
if not chunk:
start_response_args[0][1].append(('content-length', '0'))
elif isinstance(iterable, list):
start_response_args[0][1].append(
('content-length', str(sum(len(i) for i in iterable))))
else:
raise Exception('WSGI [proxy-logging]: No content-length '
'or transfer-encoding header sent and there is '
Expand Down
20 changes: 20 additions & 0 deletions test/unit/common/middleware/test_proxy_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ def __call__(self, env, start_response):
return self.body


class FakeAppNoContentLengthNoTransferEncoding(object):
def __init__(self, body=['FAKE APP']):
self.body = body

def __call__(self, env, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
while env['wsgi.input'].read(5):
pass
return self.body


class FileLikeExceptor(object):
def __init__(self):
pass
Expand Down Expand Up @@ -226,5 +237,14 @@ def test_disconnect_on_read(self):
self.assertEquals(log_parts[6], '499')
self.assertEquals(log_parts[10], '-') # read length

def test_no_content_length_no_transfer_encoding(self):
app = proxy_logging.ProxyLoggingMiddleware(
FakeAppNoContentLengthNoTransferEncoding(), {})
app.access_logger = FakeLogger()
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
resp = app(req.environ, start_response)
body = ''.join(resp)


if __name__ == '__main__':
unittest.main()

0 comments on commit 8b778c7

Please sign in to comment.