flask-compress
flask-compress copied to clipboard
Exclude User Agents from compression
Some User Agent should be excluded from compression to avoid decoding issues.
For instance, Safari 11.1.2 included in Mac OS X 10.11.6 gives this status message: Safari can't open the page. The error is: “cannot decode raw data” (NSURLErrorDomain:-1015). Its UA is: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15"
This browser can be excluded from compression by setting app.config["COMPRESS_EXCLUDE_UA"] = ['Mac OS X 10'].
Also, app.config["COMPRESS_TRACE"] = True enables to log the User Agent.
If a specific browser is unable to decode a certain type of compression, shouldn't it just say so in the Accept-Encoding HTTP header?
This is the request header:
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15
With either gzip or deflate, the browser shows:
Safari can't open the page.
"cannot decode raw data" (NSURLErrorDomain:-1015).
I have not found any relevant note on how to fix this.
I do not know whether this helps: https://stackoverflow.com/questions/32169082/safari-cannot-decode-raw-data-when-using-gzip
The only quick solution was to exclude the user agent.
I am not sure the issue relates to the page you linked, as in the relevant part of the code, it does not look like we are including any filename in the compressed content (that would be GzipFile first argument).
- It is issue happening regardless of the Python version used in the server?
- Does this happen for
deflateas well? - Is only a specific version of Safari affected?
I do not have access to Safari so I cannot do much investigation.
I am not sure the issue relates to the page you linked, as in the relevant part of the code, it does not look like we are including any filename in the compressed content (that would be GzipFile first argument).
Yes, right.
It is issue happening regardless of the Python version used in the server?
Regardless the Python version: I am using Python 3.10.4 and Python 3.7.10 on Ubuntu 22.04 LTS. Both have the issue.
Does this happen for deflate as well?
Yes
Is only a specific version of Safari affected?
Yes, I believe it is related to Safari 11.1.2 included in OS X El Capitan 10.11.6 (old MacBook Air 2009 hw).