Skip to content

Commit

Permalink
pr feedback: explain edge cases in more detail
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Demirgian authored and Jonathan Demirgian committed Nov 29, 2021
1 parent 82a4264 commit d073683
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions zappa/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,16 @@ def handler(self, event, context):
)

if response.data:
# We base64 encode for two reasons when BINARY_SUPPORT is enabled:
# - Content-Encoding is present, which is commonly used by compression mechanisms to indicate
# that the content is in br/gzip/deflate/etc encoding
# (Related: https://github.com/zappa/Zappa/issues/908). Content like this must be
# transmitted as b64.
# - The response is assumed to be some binary format (since BINARY_SUPPORT is enabled and it
# isn't application/json or text/)
if settings.BINARY_SUPPORT and response.headers.get(
"Content-Encoding"
):
# We could have a text response that's gzip
# encoded. Therefore, we base-64 encode it.
# Related: https://github.com/zappa/Zappa/issues/908
zappa_returndict["body"] = base64.b64encode(
response.data
).decode("utf-8")
Expand Down

0 comments on commit d073683

Please sign in to comment.