-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Nice fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs changeset but LGTM!
@matthewp This one's ready for another review with the non-regex solution we talked about yesterday 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smart change, this is way better. LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
base
ically perfect 👏
Changes
Closes #3586
This updates the
@astrojs/netlify/functions
adapter to check if response body is a base64 encoded string. This is needed to make sure theisBase64Encoded
flag is returned if necessaryBecause Astro's API endpoints are expected to return a standard
Response
object, the adapter doesn't have access to the rawBodyInit
object 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