Skip to content

Conversation

@svozza
Copy link
Contributor

@svozza svozza commented Nov 8, 2025

Summary

This PR adds support for base64 encoding of responses. If a handler returns an APIGatewayProxyResult or APIGatewayProxyStructuredResultV2 where the body field is a stream or an ArrayBuffer we will automatically base64 encode it. Handlers can now also just return a stream or ArrayBuffer and we will base64 encode it and set the status code to 200 and the content type to application/json.

Changes

  • Handler functions can now return ArrayBuffers and streams, either on their own or as part of a response event, these will automatically be base64 encoded.
  • Handler resolution logic detects whether to base64 encode a response and stores decision in the requestContext object in a field called isBase64Encoded. This decision is made by whether the content-encoding header is set ot the the content-type header is image, audio, or video.
  • isBase64Encoded field will only be set once, this means that users can over-ride the default detection behaviour by setting base64Encoded in the handler and it will not be changed.
  • Added unit tests to test new functionality.

Issue number: closes #4514


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@svozza svozza self-assigned this Nov 8, 2025
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Nov 8, 2025
@boring-cyborg boring-cyborg bot added event-handler This item relates to the Event Handler Utility tests PRs that add or change tests labels Nov 8, 2025
@svozza svozza force-pushed the event-handler/base64-encoding-support branch from eda40f8 to 8cba5a8 Compare November 8, 2025 01:06
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 8, 2025

return true;
}

const contentType = headers.get('content-type');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative approach here is to check if we have don't a text-based content type, i.e, if the content type is not one of text/*, application/json, application/xml, application/javascript or application/x-www-form-urlencoded then we base64 encode it. My worry is that there are other non binary types I might be missing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

event-handler This item relates to the Event Handler Utility size/L PRs between 100-499 LOC tests PRs that add or change tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: first-class support for binary responses

1 participant