From a78b2d5f46fc2ab977d66ef02af93a651458a0a4 Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Mon, 12 Nov 2012 15:02:04 -0800 Subject: [PATCH] Fix 500 on GET of many-segment manifest. The proxy_logging middleware was asserting that the response contained either a Content-Length header or a Transfer-Encoding header. If not, it would either add one (if app_iter was a list) or blow up (otherwise). This blowing up is observable on a GET request to a manifest object that references more than swift.common.constraints.CONTAINER_LISTING_LIMIT segments. If a response makes it up to eventlet.wsgi without a Content-Length header, then a "Transfer-Encoding: chunked" header is automatically stuffed into the response by eventlet. Therefore, it's not an error for a response to not have a Content-Length header, and proxy_logging should just let it happen. Fixes bug 1078113. Change-Id: I3751a8ae14dc68bab546f2746b61267a5115e252 --- swift/common/middleware/proxy_logging.py | 4 ---- .../common/middleware/test_proxy_logging.py | 19 ------------------- 2 files changed, 23 deletions(-) diff --git a/swift/common/middleware/proxy_logging.py b/swift/common/middleware/proxy_logging.py index 3cc21b4783..a63e10436f 100644 --- a/swift/common/middleware/proxy_logging.py +++ b/swift/common/middleware/proxy_logging.py @@ -205,10 +205,6 @@ class ProxyLoggingMiddleware(object): 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 content! %r' % chunk) start_response(*start_response_args[0]) bytes_sent = 0 client_disconnect = False diff --git a/test/unit/common/middleware/test_proxy_logging.py b/test/unit/common/middleware/test_proxy_logging.py index ceee8689b0..86841df5b8 100644 --- a/test/unit/common/middleware/test_proxy_logging.py +++ b/test/unit/common/middleware/test_proxy_logging.py @@ -391,25 +391,6 @@ class TestProxyLogging(unittest.TestCase): self.assertEquals(resp_body, '') self.assertEquals(log_parts[11], '-') - def test_no_content_length_no_transfer_encoding_with_str_body(self): - app = proxy_logging.ProxyLoggingMiddleware( - FakeAppNoContentLengthNoTransferEncoding( - body='line1\nline2\n', - ), {}) - app.access_logger = FakeLogger() - req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}) - resp = app(req.environ, start_response) - # Python 2.7 can have assertRaises act as a context manager, but python - # 2.6 can't. So there's this. - try: - resp_body = ''.join(resp) - except Exception as e: - self.assertEquals( - "WSGI [proxy-logging]: No content-length or transfer-encoding " - "header sent and there is content! 'l'", str(e)) - else: - self.assert_(False) - def test_req_path_info_popping(self): app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {}) app.access_logger = FakeLogger()