Skip to content

HttpApi: wrong capitalisation of properties in the headers object - not asking for headers to be case sensitive #3083

@mastazi

Description

@mastazi

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:

  1. Create a function with an HttpApi Path.
  2. In the response, return event.headers, see code snippet below.
  3. Build and then start local api with sam local start-api
  4. 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)

  1. OS: Windows 10
  2. sam --version: SAM CLI, version 1.23.0
  3. AWS region: ap-southeast-2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions