From 4168a99dcb90d95c8b44401377e4f80e2d144c02 Mon Sep 17 00:00:00 2001 From: Egor Korovin Date: Mon, 4 Apr 2022 23:44:19 +0700 Subject: [PATCH] proper encoding --- setup.py | 2 +- yappa/handlers/common.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index ac4afda..2eda757 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='yappa', - version='0.4.20', + version='0.4.21', url='https://github.com/turokg/yappa', description='Easy serverless deploy of python web applications', long_description_content_type="text/markdown", diff --git a/yappa/handlers/common.py b/yappa/handlers/common.py index 4b621fe..f455ab2 100644 --- a/yappa/handlers/common.py +++ b/yappa/handlers/common.py @@ -64,6 +64,7 @@ def get_encoding(response): for re_ in ENCODED_CONTENT_TYPES: if re_.match(content_type): return True + return False def patch_response(response): @@ -75,9 +76,10 @@ def patch_response(response): 'headers': {} } """ + is_encoded = get_encoding(response) return { 'statusCode': response.status_code, 'headers': dict(response.headers), - 'body': response.content.decode(), - 'isBase64Encoded': get_encoding(response), + 'body': response.content if is_encoded else response.content.encode(), + 'isBase64Encoded': is_encoded, }