Ticket #318 (closed defect: fixed)
gzipper middleware does not cope with zero length responses.
| Reported by: | jkp | Owned by: | ianb |
|---|---|---|---|
| Priority: | high | Milestone: | 1.3 |
| Component: | paste | Version: | released-version |
| Severity: | major | Keywords: | |
| Cc: | alice@… |
Description
If an application starts a response but returns only "" then the gzipper middleware throws an exception:
self.finish_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 320, in finish_request self.RequestHandlerClass(request, client_address, self) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 615, in __init__ self.handle() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Paste-1.7.2-py2.6.egg/paste/httpserver.py", line 442, in handle BaseHTTPRequestHandler.handle(self) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.py", line 329, in handle self.handle_one_request() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Paste-1.7.2-py2.6.egg/paste/httpserver.py", line 437, in handle_one_request self.wsgi_execute() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Paste-1.7.2-py2.6.egg/paste/httpserver.py", line 290, in wsgi_execute self.wsgi_write_chunk(chunk) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Paste-1.7.2-py2.6.egg/paste/httpserver.py", line 125, in wsgi_write_chunk "Content returned before start_response called") RuntimeError: Content returned before start_response called
The reason is that it is testing the result wrongly:
if app_iter: response.finish_response(app_iter)
Changing the test to test for None instead fixes the issue:
def __call__(self, environ, start_response): if 'gzip' not in environ.get('HTTP_ACCEPT_ENCODING', ''): # nothing for us to do, so this middleware will # be a no-op: return self.application(environ, start_response) response = GzipResponse(start_response, self.compress_level) app_iter = self.application(environ, response.gzip_start_response) if app_iter is not None: response.finish_response(app_iter) return response.write()
Change History
Note: See
TracTickets for help on using
tickets.
