-
Notifications
You must be signed in to change notification settings - Fork 457
fix: resemble Netlify Production logic for base64 encoding more closely #3631
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
Changes from all commits
e356278
e63caa3
f764ce4
3b404d9
29fdf42
e05c16a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,6 @@ const chalk = require('chalk') | |
| const { warn } = require('../../utils/command-helpers') | ||
| const { getLogMessage } = require('../log') | ||
|
|
||
| const BASE_64_MIME_REGEXP = /image|audio|video|application\/pdf|application\/zip|applicaton\/octet-stream/i | ||
|
|
||
| const DEFAULT_LAMBDA_OPTIONS = { | ||
| verboseLevel: 3, | ||
| } | ||
|
|
@@ -21,8 +19,41 @@ const detectAwsSdkError = ({ error }) => { | |
|
|
||
| const formatLambdaError = (err) => chalk.red(`${err.errorType}: ${err.errorMessage}`) | ||
|
|
||
| // should be equivalent to https://github.com/netlify/proxy/blob/main/pkg/functions/request.go#L105 | ||
| const exceptionsList = new Set([ | ||
| 'application/csp-report', | ||
| 'application/graphql', | ||
| 'application/json', | ||
| 'application/javascript', | ||
| 'application/x-www-form-urlencoded', | ||
| 'application/x-ndjson', | ||
| 'application/xml', | ||
| ]) | ||
|
|
||
| /** | ||
| * @param {string | undefined} contentType | ||
| * @returns {boolean} | ||
| */ | ||
| const shouldBase64Encode = function (contentType) { | ||
| return Boolean(contentType) && BASE_64_MIME_REGEXP.test(contentType) | ||
| if (!contentType) { | ||
| return true | ||
| } | ||
|
|
||
| contentType = contentType.toLowerCase() | ||
|
|
||
| if (contentType.startsWith('text/')) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why we can't move these to a single condition?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like how each of the conditions is its own case, à la "if it's a text, don't encode; if it's another content-type encoded as json or xml, don't encode; here's a set of exceptions we don't encode". Moving them into a single condition would make that grouping harder to see. Can you elaborate on why we should move them into a single condition?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I think having 3 termination points when you can have 1 makes it harder to trace and debug. I also don't see how having a single condition makes the grouping harder to see. It's not a big deal though, and I respect the personal preference if you think it adds more clarity. |
||
| return false | ||
| } | ||
|
|
||
| if (contentType.endsWith('+json') || contentType.endsWith('+xml')) { | ||
| return false | ||
| } | ||
|
|
||
| if (exceptionsList.has(contentType)) { | ||
| return false | ||
| } | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| const styleFunctionName = (name) => chalk.magenta(name) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.