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

Add Compressed Text Support #1092

Closed
wants to merge 5 commits into from

Conversation

monkut
Copy link
Collaborator

@monkut monkut commented Dec 8, 2021

Description

Currently, in version 0.54.1, when compressed text is sent in response, zappa throws the following exception:

{'message': 
'An uncaught exception happened while servicing this request. You can investigate this with the `zappa tail` command.', 'traceback': 
['Traceback (most recent call last):\\n', 
'  File \"/var/task/handler.py\", line 596, in handler\\n
    zappa_returndict[\"body\"] = response.get_data(as_text=True)\\n', 
'  File \"/var/task/werkzeug/wrappers/response.py\", 
line 313, in get_data\\n    return rv.decode(self.charset)\\n', 
\"UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte\\n\
"]}

This is 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

#908

@monkut
Copy link
Collaborator Author

monkut commented Dec 8, 2021

(Needs testcases

Looks like some test cases were prepared in the original pr:

Miserlou/Zappa#2170

@monkut monkut changed the title Add/binary text support 541 Add Compressed Text Support Dec 8, 2021
@monkut
Copy link
Collaborator Author

monkut commented Dec 8, 2021

still seems to have issues with serving *.woff files.

@Quidge
Copy link

Quidge commented Dec 8, 2021

@monkut I extended your original PR in miserlou/zappa and added some tests + formatting over in this PR.

My co has been using a fork based on that PR for some time without issue, though we don't serve .woff files. Could leverage the work + test base in that PR could be extended to include woff files possibly.

@monkut
Copy link
Collaborator Author

monkut commented Jan 17, 2022

closing this PR as the PR below solves the same issue and is further along.

#971

@monkut monkut closed this Jan 17, 2022
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 this pull request may close these issues.

2 participants