Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome ranged requests incorrectly fallback to any #19

Closed
ziddey opened this issue Feb 12, 2021 · 2 comments
Closed

Chrome ranged requests incorrectly fallback to any #19

ziddey opened this issue Feb 12, 2021 · 2 comments

Comments

@ziddey
Copy link

ziddey commented Feb 12, 2021

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
Copy link
Collaborator

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

  • we should not allow fallback_to_any when the associated q=0
  • algo = '*' should not be passed to algos_by_quality
  • identity is not handled

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
Copy link
Collaborator

Closed with 86b4730 and 8ae3b3c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants