Skip to content

Commit

Permalink
fix: handle content-type headers with charset (#4240)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Feb 9, 2022
1 parent ef9e536 commit 9782c38
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/functions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const shouldBase64Encode = function (contentType) {
return true
}

const [contentTypeSegment] = contentType.split(';')
contentType = contentTypeSegment
contentType = contentType.toLowerCase()

if (contentType.startsWith('text/')) {
Expand Down
25 changes: 25 additions & 0 deletions tests/integration/20.command.functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,4 +814,29 @@ test('should inject env variables', async (t) => {
})
})

test('should handle content-types with charset', async (t) => {
await withSiteBuilder('site-with-env-function', async (builder) => {
await builder
.withNetlifyToml({
config: { functions: { directory: 'functions' } },
})
.withFunction({
path: 'echo-event.js',
handler: async (event) => ({
statusCode: 200,
body: JSON.stringify(event),
}),
})
.buildAsync()

const port = await getPort()
await withFunctionsServer({ builder, args: ['--port', port], port }, async () => {
const response = await got(`http://localhost:${port}/.netlify/functions/echo-event`, {
headers: { 'content-type': 'application/json; charset=utf-8' },
}).json()
t.is(response.isBase64Encoded, false)
})
})
})

/* eslint-enable require-await */

1 comment on commit 9782c38

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 440 MB

Please sign in to comment.