Skip to content

Commit 5269d01

Browse files
author
Keyur
committed
Fix: Encode body and set the transfer encoding to base64
Fix: Encode body and set the transfer encoding to base64
1 parent aa45eb5 commit 5269d01

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

moesif_aws_lambda/middleware.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,13 @@ def process_body(self, body_wrapper):
132132
body = body_wrapper.get('body')
133133
transfer_encoding = 'json'
134134
except Exception as e:
135-
return body_wrapper.get('body'), 'base64'
135+
body = base64.b64encode(str(body_wrapper['body']).encode("utf-8"))
136+
if isinstance(body, str):
137+
return str(body).encode("utf-8"), 'base64'
138+
elif isinstance(body, (bytes, bytearray)):
139+
return str(body, "utf-8"), 'base64'
140+
else:
141+
return str(body), 'base64'
136142
return body, transfer_encoding
137143

138144
def before(self, event, context):

0 commit comments

Comments
 (0)