From d0736833b68b3709ef875d54401f948576af8fc2 Mon Sep 17 00:00:00 2001 From: Jonathan Demirgian Date: Sun, 28 Nov 2021 18:52:58 -0500 Subject: [PATCH] pr feedback: explain edge cases in more detail --- zappa/handler.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/zappa/handler.py b/zappa/handler.py index 8d95718f..488d0f31 100644 --- a/zappa/handler.py +++ b/zappa/handler.py @@ -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")