Skip to content

Commit 06b6fc5

Browse files
committed
support multiple headers with the same name
1 parent 09c8f8a commit 06b6fc5

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,4 @@ app.use(awsServerlessExpressMiddleware.eventContext())
8080
- May be more expensive for high-traffic apps
8181
- Cannot use native libraries (aka [Addons](https://nodejs.org/api/addons.html)) unless you package your app on an EC2 machine running Amazon Linux
8282
- Stateless only
83-
- Multiple headers with same name not currently supported
8483
- API Gateway has a timeout of 30 seconds, and Lambda has a maximum execution time of 5 minutes.

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
'use strict'
1616
const http = require('http')
17+
const binarycase = require('binary-case');
1718

1819
function getPathWithQueryStringParams(event) {
1920
const queryStringKeys = Object.keys(event.queryStringParameters || {})
@@ -57,7 +58,12 @@ function forwardResponseToApiGateway(server, response, context) {
5758

5859
Object.keys(headers)
5960
.forEach(h => {
60-
if(Array.isArray(headers[h])) headers[h] = headers[h].join(',')
61+
if(Array.isArray(headers[h])) {
62+
headers[h].forEach((value, i) => {
63+
headers[binarycase(h, i + 1)] = value;
64+
});
65+
delete headers[h];
66+
}
6167
})
6268

6369
const contentType = headers['content-type']

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@
3232
},
3333
"scripts": {
3434
"test": "jest"
35+
},
36+
"dependencies": {
37+
"binary-case": "^1.0.0"
3538
}
3639
}

0 commit comments

Comments
 (0)