Adds support base64 encoding in Netlify Functions#3592
Conversation
🦋 Changeset detectedLatest commit: 9b0d889 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Is the use-case about images here? I'm worried about this regular expression and applying it to every request. I'm thinking that it shouldn't be on the developer to base64 encode their images, but rather just include the right Content-Type. And then the adapter could be the one to apply the base64 encoding. It's a matter of the base64 encoding being an implementation detail of the adapter and not something the application should need to concern itself with. Also consider cases where you base64 something and want it to be delivered as a string (using text/plain). Just feels like using the mimetype here is a better approach. Happy to discuss. |
natemoo-re
left a comment
There was a problem hiding this comment.
I initially approved this but on second-thought I agree with @matthewp's suggestion that we should handle this invisibly if at all possible.
|
Synced with Matthew offline and think we landed on a better approach that avoids the rather nasty regex 👍 Updated PR to follow! |
bholmesdev
left a comment
There was a problem hiding this comment.
Needs changeset but LGTM!
|
@matthewp This one's ready for another review with the non-regex solution we talked about yesterday 👍 |
natemoo-re
left a comment
There was a problem hiding this comment.
Smart change, this is way better. LGTM!
* Adding support for base64 encoded responses in Netlify Functions * chore: add changeset * removing the regex check for a more simple header-based check * nit: cleaning up the readme a bit
Changes
Closes #3586
This updates the
@astrojs/netlify/functionsadapter to check if response body is a base64 encoded string. This is needed to make sure theisBase64Encodedflag is returned if necessaryBecause Astro's API endpoints are expected to return a standard
Responseobject, the adapter doesn't have access to the rawBodyInitobject that was used. The solution here is to encode the response body in the API endpoint, allowing the adapter to check whetherresponse.text()is a base64 string.Testing
Added a test suite to verify that base64 responses are returned as expected
Docs
N/A