Skip to content

Commit ac577b8

Browse files
authored
fix(event_handler): fix compress handling (#3420)
1 parent dc9a237 commit ac577b8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -789,18 +789,19 @@ def _route(self, event: ResponseEventT, cors: Optional[CORSConfig]):
789789

790790
def build(self, event: ResponseEventT, cors: Optional[CORSConfig] = None) -> Dict[str, Any]:
791791
"""Build the full response dict to be returned by the lambda"""
792+
793+
# We only apply the serializer when the content type is JSON and the
794+
# body is not a str, to avoid double encoding
795+
if self.response.is_json() and not isinstance(self.response.body, str):
796+
self.response.body = self.serializer(self.response.body)
797+
792798
self._route(event, cors)
793799

794800
if isinstance(self.response.body, bytes):
795801
logger.debug("Encoding bytes response with base64")
796802
self.response.base64_encoded = True
797803
self.response.body = base64.b64encode(self.response.body).decode()
798804

799-
# We only apply the serializer when the content type is JSON and the
800-
# body is not a str, to avoid double encoding
801-
elif self.response.is_json() and not isinstance(self.response.body, str):
802-
self.response.body = self.serializer(self.response.body)
803-
804805
return {
805806
"statusCode": self.response.status_code,
806807
"body": self.response.body,

0 commit comments

Comments
 (0)