GZIP compression impossible?
- Dominant language
- Python
- Stars
- 11.1k
- Forks
- 1k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 2
Description
**Problem:**
Probably something HTTPS related is being done to the body of the response only once deployed, a local service does not have this issue (which might be another issue - that there are discrepancies so big between local and the real thing). Trying to follow the https://aws.github.io/chalice/tutorials/basicrestapi.html?highlight=gzip#gzip-compression-for-json I endup with a `UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte` ONLY on a deployed lambda. `0x8b` is a part of GZIP's [magic number](https://en.wikipedia.org/wiki/List_of_file_signatures).
**Steps to reproduce:**
Given the example from: https://aws.github.io/chalice/tutorials/basicrestapi.html?highlight=gzip#gzip-compression-for-json
```python
import json
import gzip
from chalice import Chalice, Response
app = Chalice(app_name='compress-response')
app.api.binary_types.append('application/json')
@app.route('/')
def index():
blob = json.dumps({'hello': 'world'}).encode('utf-8')
payload = gzip.compress(blob)
custom_headers = {
'Content-Type': 'application/json',
'Content-Encoding': 'gzip'
}
return Response(body=payload, # this is bytes
status_code=200,
headers=custom_headers)
```
1. deploy it with `chalice local` - all is good
2. deploy with `chalice deploy` - you will get the `UnicodeDecodeError`
**Expected behavior:**
Both instances should work the same - respond with a gzip compressed response.
This is potentially related to #1666
Thank you for looking into this.
Contributor guide
Research direction
Start with the linked basic REST API gzip example and reproduce it with both `chalice local` and `chalice deploy`. Compare how the deployed response handles the byte payload, `binary_types`, and `Content-Encoding: gzip`; done means both environments return the compressed response without a UnicodeDecodeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- api, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100