feat(event-handler): add first-class support for binary responses #4723
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Summary
This PR adds support for base64 encoding of responses. If a handler returns an
APIGatewayProxyResultorAPIGatewayProxyStructuredResultV2where thebodyfield is a stream or anArrayBufferwe will automatically base64 encode it. Handlers can now also just return a stream orArrayBufferand we will base64 encode it and set the status code to 200 and the content type toapplication/json.Changes
ArrayBuffers and streams, either on their own or as part of a response event, these will automatically be base64 encoded.requestContextobject in a field calledisBase64Encoded. This decision is made by whether thecontent-encodingheader is set ot the thecontent-typeheader is image, audio, or video.isBase64Encodedfield will only be set once, this means that users can over-ride the default detection behaviour by settingbase64Encodedin the handler and it will not be changed.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.