Skip to content

Set isBase64Encoded based on HTTP response body type#2

Open
villain-b wants to merge 1 commit intoramosbugs:mainfrom
villain-b:main
Open

Set isBase64Encoded based on HTTP response body type#2
villain-b wants to merge 1 commit intoramosbugs:mainfrom
villain-b:main

Conversation

@villain-b
Copy link
Contributor

Summary

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.

Tests

Without this change, an API that returns a binary string (ie. OpenAPI type string and format binary leading to a Rust Vec<u8> type) with the appropriate Content-type set 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-type still returns a base64-encoded string for the same API endpoint.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant