Zappa icon indicating copy to clipboard operation
Zappa copied to clipboard

[Migrated] Update BINARY_SUPPORT to use Content-Encoding to identify if data is binary

Open jneves opened this issue 4 years ago • 2 comments

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

jneves avatar Feb 20 '21 13:02 jneves

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.

Quidge avatar Apr 08 '21 21:04 Quidge

This also causes failure when it is useful to compress JSON API responses ...

cdruck avatar Jun 01 '21 08:06 cdruck

released in 0.56.0, closing.

monkut avatar Dec 01 '22 10:12 monkut