Search code examples
pythonflaskgziptornadowsgi

Gzip response in Flask/Tornado


I have a simple Flask app running. To serve I use Tornado. The code that starts the server looks like this:

# Run the app in server mode
http_server = HTTPServer(WSGIContainer(app))
http_server.listen(port)
IOLoop.instance().start()

Where app is the Flask WSGI app object (app = Flask(__name__)).

Now the server responds every request with the entire JSON answer, is there a (simple) way of returning Gzipped data? On the Tornado site I found http://www.tornadoweb.org/documentation/releases/v2.1.0.html?highlight=gzip, so it must be possible with Tornado, but a Flask solution is also great.


Solution

  • It just appears weird to set up an nginx only to have gzip compression.

    Now I use this http://code.google.com/p/ibkon-wsgi-gzip-middleware/, it's good.