Skip to content

fix(event_handler): fix compress handling #3420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,18 +789,19 @@ def _route(self, event: ResponseEventT, cors: Optional[CORSConfig]):

def build(self, event: ResponseEventT, cors: Optional[CORSConfig] = None) -> Dict[str, Any]:
"""Build the full response dict to be returned by the lambda"""

# We only apply the serializer when the content type is JSON and the
# body is not a str, to avoid double encoding
if self.response.is_json() and not isinstance(self.response.body, str):
self.response.body = self.serializer(self.response.body)

self._route(event, cors)

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

# We only apply the serializer when the content type is JSON and the
# body is not a str, to avoid double encoding
elif self.response.is_json() and not isinstance(self.response.body, str):
self.response.body = self.serializer(self.response.body)

return {
"statusCode": self.response.status_code,
"body": self.response.body,
Expand Down