diff --git a/package.json b/package.json index c6071667..8b73d50c 100644 --- a/package.json +++ b/package.json @@ -52,5 +52,5 @@ "staged": "lint-staged", "test": "./node_modules/.bin/jest" }, - "version": "4.4.0" + "version": "4.4.1" } diff --git a/src/server/proxyEvent.js b/src/server/proxyEvent.js index 70b7c2d0..e910223f 100644 --- a/src/server/proxyEvent.js +++ b/src/server/proxyEvent.js @@ -4,10 +4,15 @@ const handleRequestResponse = require('./handleRequestResponse'); const http = require('http'); const url = require('url'); +const cleanHeaders = (headers) => + Object.keys(headers) + .filter((header) => typeof headers[header] !== 'undefined') + .reduce((result, header) => ({ ...result, [header]: headers[header] }), {}); + const proxyEvent = (event, socketPath) => new Promise((resolve) => { const requestOptions = { - headers: event.headers, + headers: cleanHeaders(event.headers), method: event.httpMethod, path: url.format({ pathname: event.path, query: event.queryStringParameters }), socketPath, diff --git a/tests/server.test.js b/tests/server.test.js index 06ab27dc..46a9cb94 100644 --- a/tests/server.test.js +++ b/tests/server.test.js @@ -41,3 +41,17 @@ test('basic test', async () => { await expect(response.headers['content-length']).toEqual('12'); await expect(response.headers['content-type']).toEqual('text/html; charset=utf-8'); }); + +test('iframe sends undefined cookie', async () => { + const app = express(); + const noCookieEvent = { ...event }; + + noCookieEvent.headers.cookie = undefined; + noCookieEvent.headers.Cookie = undefined; + + app.get('/', (req, res) => res.send('Hello World!')); + + const response = await lambdaServer(app, true)(noCookieEvent); + + await expect(response.body).toEqual('SGVsbG8gV29ybGQh'); +});