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.
The simplest way is to use Nginx, as Nikolay suggested. It won't add much overhead.
With tornado.web.Application
, you can just pass compress_response=True
when initializing the app. Since you're using a Flask, that won't work. You could look at the Tornado source and see what it's doing, but that won't be simple.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With