Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.89k stars 1.21k forks source link

Update BINARY_SUPPORT to use Content-Encoding to identify if data is binary #2170

Open monkut opened 3 years ago

monkut commented 3 years ago

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":

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

coveralls commented 3 years ago

Coverage Status

Coverage decreased (-0.2%) to 72.821% when pulling 14658ce60ecbe4a58a523d7585ed3c8a7e269e8d on monkut:master into 0c8d99ddbc297124d93c166652013abba50ee86e on Miserlou:master.