-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Description:
Edit 25/07/2021 I am not suggesting that headers be case sensitive, I understand this can't be done, I'm asking for the headers object properties to be lowercase so it matches API Gateway
I have this function:
fakeFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/handlers.fake
Description: A Lambda function.
Events:
Api:
Type: HttpApi
Properties:
Path: /my-path/
Method: get
if I send a header called “Myheader” in the request, then when running sam local start-api, the function will be able to access its value in event.headers.Myheader - note that Myheader is capitalised. But after deployment, API Gateway will store the value in event.headers.myheader. So, in order to have my code work both in SAM and in the cloud, I have to do something like (assuming the function is in Node.js):
let myvar = '';
if (process.env.AWS_SAM_LOCAL) {
myvar = event.headers.Myheader;
} else {
myvar = event.headers.myheader;
}
Steps to reproduce:
- Create a function with an HttpApi Path.
- In the response, return
event.headers, see code snippet below. - Build and then start local api with
sam local start-api - Call the function from an http client, and send some arbitrarily named headers with the request, e.g.
Foo: bar, Baz: bar.
const response = {
statusCode: 200,
body: JSON.stringify(event.headers),
};
return response;
Observed result:
In the response, you will see those headers will be capitalised:
{
"Foo": "bar",
"Baz": "bar"
}
Expected result:
The expected result is that the headers should be not capitalised, which is the same behaviour that AWS Api Gateway has in production:
{
"foo": "bar",
"baz": "bar"
}
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Windows 10
sam --version: SAM CLI, version 1.23.0- AWS region: ap-southeast-2