Skip to content

Commit

Permalink
Merge pull request #444 from Prefinem/clean-headers
Browse files Browse the repository at this point in the history
adding cleanHeaders to proxyEvent
  • Loading branch information
William authored Oct 25, 2021
2 parents c1c3972 + dda0d6b commit 1477abb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
"staged": "lint-staged",
"test": "./node_modules/.bin/jest"
},
"version": "4.4.0"
"version": "4.4.1"
}
7 changes: 6 additions & 1 deletion src/server/proxyEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions tests/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit 1477abb

Please sign in to comment.