CodeGenieApp / CodeGenieApp/serverless-express

`headers` is always replaced by `multiValueHeaders` with ALB events response

Open
#464 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.3k
Forks
674
PR merge metrics
No merged PRs in 30d

Description

**Context:** upgrading from 3.3.8 to 4.3.11.

`headers` is always replaced by `multiValueHeaders` : https://github.com/vendia/serverless-express/blob/6adac653fe1daf1dd44ff6aa17dbf08f07662173/src/event-sources/aws/alb.js#L40-L54

But according to https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers, it should only happen when the multi-value headers feature is enabled on the target group.

I tried to put back `headers` with a custom `getResponse` mapper :
```javascript
const customResponse = ({ statusCode, body, headers, isBase64Encoded }) => {
return {
statusCode,
body,
headers,
isBase64Encoded,
};
};
```

But then I get :
```javascript
"errorMessage": "eventSource.getRequest is not a function",
"stack": [
"TypeError: eventSource.getRequest is not a function",
" at forwardRequestToNodeServer (/var/task/server.js:41241:37)",
" at /var/task/server.js:40578:9",
" at new Promise ()",
" at proxy (/var/task/server.js:40565:12)",
" at Runtime.handler (/var/task/server.js:40602:12)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
```

So it seems that if `getResponse` is set, `getRequest`has to be set as well. This is not ideal as the request mapper is not exported and cannot be used directly.

I don't know what could be the best solution to address this, ​but at least allowing to set only `getResponse` mapper should allow us to fix the initial issue.

Sister issue but for API Gateway : https://github.com/vendia/serverless-express/issues/437

Contributor guide

Open the contributing guide

Research direction

Start with src/event-sources/aws/alb.js at the linked response-mapping code and read the AWS ALB multi-value headers documentation. Trace how getResponse and getRequest are selected, then verify that single-value headers are preserved when the feature is disabled and that a custom getResponse mapper can be used alone.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, express, javascript, node.js
Domain
api, backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.