Merge "Make proxy-logging more like eventlet.posthook"
This commit is contained in:
commit
04b77fdf4d
@ -167,6 +167,9 @@ class ProxyLoggingMiddleware(object):
|
||||
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 '
|
||||
|
@ -34,6 +34,17 @@ class FakeApp(object):
|
||||
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
|
||||
@ -226,5 +237,14 @@ class TestProxyLogging(unittest.TestCase):
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user