Skip to content

Commit a987fee

Browse files
hffmnnChristian Hoffmann
andauthored
fix: make headers an object instead of an array (#386)
* fix: make headers an object instead of an array * fix: add unit test Co-authored-by: Christian Hoffmann <352753+hffmnn@users.noreply.github.co>
1 parent 4b93bcb commit a987fee

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

__tests__/unit.api-gateway-v2.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const eventSources = require('../src/event-sources')
2+
const testUtils = require('../src/event-sources/utils.test')
3+
4+
const apiGatewayEventSource = eventSources.getEventSource({
5+
eventSourceName: 'AWS_API_GATEWAY_V2'
6+
})
7+
8+
test('request has correct headers', () => {
9+
const req = getReq()
10+
// see https://github.com/vendia/serverless-express/issues/387
11+
expect(typeof req).toEqual('object')
12+
expect(JSON.stringify(req.headers)).toEqual(
13+
'{"cookie":"","host":"localhost:9000","user-agent":"curl/7.64.1","accept":"*/*","x-forwarded-proto":"http","x-forwarded-port":"9000"}'
14+
)
15+
})
16+
17+
function getReq () {
18+
const event = testUtils.sam_httpapi_event
19+
const request = apiGatewayEventSource.getRequest({ event })
20+
return request
21+
}

src/event-sources/aws/api-gateway-v2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function getRequestValuesFromApiGatewayEvent ({ event }) {
1818
search: rawQueryString
1919
})
2020

21-
const headers = []
21+
const headers = {}
2222

2323
if (cookies) {
2424
headers.cookie = cookies.join('; ')

src/event-sources/utils.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ describe("getEventSourceNameBasedOnEvent", () => {
5050
expect(result).toEqual("AWS_API_GATEWAY_V2");
5151
});
5252
});
53+
54+
module.exports = {
55+
sam_httpapi_event,
56+
};

0 commit comments

Comments
 (0)