colour-science / flask-compress

Compress responses of your Flask application.
MIT License
117 stars 27 forks source link

Chrome ranged requests incorrectly fallback to any #19

Closed ziddey closed 3 years ago

ziddey commented 3 years ago

For a ranged request, Chrome sends the accept-encoding header as identity;q=1, *;q=0

While the *;q=0 is redundant with identity;q=1 since identity is always acceptable, it causes flask-compress to fallback to any and improperly compress the response, resulting in ERR_CONTENT_DECODING_FAILED in Chrome.

A simple fix would be to simply if algo=='*' and not quality: continue or also require quality for fallback_to_any in _choose_compress_algorithm.

https://github.com/colour-science/flask-compress/blob/master/flask_compress.py#L118-L136

A more robust/proper approach would be to add identity as an enabled algorithm and then also check for chosen_algorithm == 'identity' in after_request to skip compression.

https://github.com/colour-science/flask-compress/blob/master/flask_compress.py#L167-L174

alexprengere commented 3 years ago

Hello, thanks for the PR! Indeed a few small things are wrong the current code:

I pushed a few commits that fix this. I did not merge your PR since it broke a few tests. Can you please confirm this works for you? I will make a release then.

alexprengere commented 3 years ago

Closed with 86b47306842496cfbb9d7b76f4e15f6f39485ab8 and 8ae3b3cfb69d76929418e6817ccde45fd292e545