Set isBase64Encoded based on HTTP response body type#2
Open
villain-b wants to merge 1 commit intoramosbugs:mainfrom
Open
Set isBase64Encoded based on HTTP response body type#2villain-b wants to merge 1 commit intoramosbugs:mainfrom
isBase64Encoded based on HTTP response body type#2villain-b wants to merge 1 commit intoramosbugs:mainfrom
Conversation
This commit changes the way `isBase64Encoded` attribute is set for the Lambda HTTP response. Currently, it is hardcoded to `false` which prevents an API endpoint from returning binary data to the caller. The problem is that Lambda uses this attribute to signal API Gateway that the response is base64 encoded which is then used by API Gateway to possibly convert the response payload to binary before sending it back to the caller. I think the change is safe because it doesn't actuate any change in isolation: an API Gateway must first be configured to convert a base64 encoded payload into binary. This setting is the `Binary media types` which indicates which `content-type` should be treated as binary (both from client and server side). More information can be found at https://docs.aws.amazon.com/apigateway/latest/developerguide/lambda-proxy-binary-media.html.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 commit changes the way
isBase64Encodedattribute is set for the Lambda HTTP response. Currently, it is hardcoded tofalsewhich prevents an API endpoint from returning binary data to the caller. The problem is that Lambda uses this attribute to signal API Gateway that the response is base64 encoded which is then used by API Gateway to possibly convert the response payload to binary before sending it back to the caller.I think the change is safe because it doesn't actuate any change in isolation: an API Gateway must first be configured to convert a base64 encoded payload into binary. This setting is the
Binary media typeswhich indicates whichcontent-typeshould be treated as binary (both from client and server side). More information can be found at https://docs.aws.amazon.com/apigateway/latest/developerguide/lambda-proxy-binary-media.html.Tests
Without this change, an API that returns a binary string (ie. OpenAPI type
stringand formatbinaryleading to a RustVec<u8>type) with the appropriateContent-typeset sends back a base64 encoded string to the caller. With the change, this setup works as intended and the caller receives a binary stream.I also tested that with the change, an API Gateway that has not configured the Binary Media Types for the appropriate
Content-typestill returns a base64-encoded string for the same API endpoint.