Zappa
Zappa copied to clipboard
[Migrated] Update BINARY_SUPPORT to use Content-Encoding to identify if data is binary
Originally from: https://github.com/Miserlou/Zappa/issues/2170 by monkut
Description
Alternative solution to https://github.com/Miserlou/Zappa/issues/2080 intended to allow BINARY and text by making use of Content-Encoding header in the response.
When using whitenoise for caching, which provides compression, binary types may include mimetypes, "text/", "application/json":
- response.mimetype.startswith("text/")
- response.mimetype == "application/json"
Assuming that Content-Encoding will be set (as whitenoise apparently does) this allows compression to be applied to assets which have mimetypes "text/" and "application/json", while allowing for uncompressed "text/" and "application/json" still to be served.
About Content-Encoding: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
Not sure if this works for all use cases, but it currently appears to work for my workcase where whitenoise is performing compression of text/json files intended for caching, while still allowing text for html.
GitHub Issues
https://github.com/Miserlou/Zappa/issues/2080
Our team also ran into this issue. We forked the Zappa repo and merged this older PR: bfcb649
(#2141).
@jneves Is there anything you would like to see that could help this older PR code to get over the line and into main? AFAICT it didn't pass original CI because it decreased coverage by 0.03%
.
I'd be happy to add some tests for this scenario and increase coverage.
This also causes failure when it is useful to compress JSON API responses ...
released in 0.56.0, closing.