Skip to content

Commit

Permalink
fix: make headers an object instead of an array (#386)
Browse files Browse the repository at this point in the history
* fix: make headers an object instead of an array

* fix: add unit test

Co-authored-by: Christian Hoffmann <352753+hffmnn@users.noreply.github.co>
  • Loading branch information
hffmnn and Christian Hoffmann authored May 31, 2021
1 parent 4b93bcb commit a987fee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions __tests__/unit.api-gateway-v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const eventSources = require('../src/event-sources')
const testUtils = require('../src/event-sources/utils.test')

const apiGatewayEventSource = eventSources.getEventSource({
eventSourceName: 'AWS_API_GATEWAY_V2'
})

test('request has correct headers', () => {
const req = getReq()
// see https://github.com/vendia/serverless-express/issues/387
expect(typeof req).toEqual('object')
expect(JSON.stringify(req.headers)).toEqual(
'{"cookie":"","host":"localhost:9000","user-agent":"curl/7.64.1","accept":"*/*","x-forwarded-proto":"http","x-forwarded-port":"9000"}'
)
})

function getReq () {
const event = testUtils.sam_httpapi_event
const request = apiGatewayEventSource.getRequest({ event })
return request
}
2 changes: 1 addition & 1 deletion src/event-sources/aws/api-gateway-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function getRequestValuesFromApiGatewayEvent ({ event }) {
search: rawQueryString
})

const headers = []
const headers = {}

if (cookies) {
headers.cookie = cookies.join('; ')
Expand Down
4 changes: 4 additions & 0 deletions src/event-sources/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ describe("getEventSourceNameBasedOnEvent", () => {
expect(result).toEqual("AWS_API_GATEWAY_V2");
});
});

module.exports = {
sam_httpapi_event,
};

0 comments on commit a987fee

Please sign in to comment.