diff --git a/src/lib/functions/utils.js b/src/lib/functions/utils.js index 6162362f319..09acdc02be8 100644 --- a/src/lib/functions/utils.js +++ b/src/lib/functions/utils.js @@ -38,6 +38,8 @@ const shouldBase64Encode = function (contentType) { return true } + const [contentTypeSegment] = contentType.split(';') + contentType = contentTypeSegment contentType = contentType.toLowerCase() if (contentType.startsWith('text/')) { diff --git a/tests/integration/20.command.functions.test.js b/tests/integration/20.command.functions.test.js index 94096f8c3ac..d35271adcb4 100644 --- a/tests/integration/20.command.functions.test.js +++ b/tests/integration/20.command.functions.test.js @@ -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 */