Sanic: Gzip compression middleware example, static files have empty body

Created on 17 Feb 2017  Â·  6Comments  Â·  Source: sanic-org/sanic

I couldn't see a way to compress responses and accept compressed requests automatically so I wrote this:
https://gist.github.com/lukestanley/a6cb1daffd2f0ed9829b6b96e067d8cf
I haven't profiled it but it seems to work well for my purposes.
However it doesn't compress static files when requested, as they have an empty response body.

Most helpful comment

I'm a fan. Maybe rewrite it as an extension and include it in the extensions documentation?

All 6 comments

your gist works for me, the response has an empty body when its returning a 304 (i.e. the client already has the resource). Try clearing your cache while testing ctrl+shift+r in chrome

I'm a fan. Maybe rewrite it as an extension and include it in the extensions documentation?

I had this extension on the backburner for a while, just published it: sanic_compress for gzipping responses.

It's basically a port of Flask-Compress.

Closing for #463

Brotli — annother choice

Thanks for pointing out the 304 status @abuckenheimer. You are welcome to do whatever with the example gist.

Was this page helpful?
0 / 5 - 0 ratings