Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalise headers dictionary keys: fixes issues 1860, 3083 etc. #3114

Closed
wants to merge 8 commits into from

Conversation

mastazi
Copy link

@mastazi mastazi commented Jul 25, 2021

Which issue(s) does this change fix?

fixes #1860, #3083 etc.

Why is this change necessary?

In API Gateway HTTP API event all headers are stored in the headers dictionary always lowercase, for example these raw headers:

Foo: baz
bar: baz

note how one header name is capitalised (Foo) and the other isn't (bar).

In API Gateway, this will result in

"event": {
  "headers": {
    "foo": "baz",
    "bar": "baz"
  }
}

note how foo and bar are both lowercase.

SAM will also treat headers as case-insensitive but unfortunately the case is capitalised instead of lowercase:

"event": {
  "headers": {
    "Foo": "baz",
    "Bar": "baz"
  }
}

this PR makes SAM behave like API Gateway.

How does it address the issue?

By making the keys of the headers dictionary lowercase, as they are in API Gateway.

What side effects does this change have?

users who were dealing with this inconsistency as in the example below, will have to modify their code:

if (process.env.AWS_SAM_LOCAL) {
    myvar  = event.headers.Myheader;
} else {
    myvar = event.headers.myheader;
}

because now myheader will be found both in SAM Local and in API Gateway. So the if-else condition is not required.

Checklist

  • Add input/output type hints to new functions/methods
  • Write design document (Do I need to write a design document?)
  • Write unit tests
  • Write/update functional tests
  • Write/update integration tests
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mastazi
Copy link
Author

mastazi commented Jul 25, 2021

Please allow me 1-2 days I will fix tests failing.
I would put the PR as draft but for some reason I don't see the button to convert to draft.

@mastazi mastazi changed the title fixes issues 1860, 3083 etc. headers dictionary keys: fixes issues 1860, 3083 etc. Jul 25, 2021
@mastazi mastazi changed the title headers dictionary keys: fixes issues 1860, 3083 etc. Normalise headers dictionary keys: fixes issues 1860, 3083 etc. Jul 25, 2021
@mastazi
Copy link
Author

mastazi commented Jul 26, 2021

Unfortunately my local linter settings polluted this PR. I am closing it and will reopen a new one.

@mastazi mastazi closed this Jul 26, 2021
@mastazi mastazi deleted the fix-event-http-headers branch July 26, 2021 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Headers are received in Camel-Case
1 participant