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

made headers dictionary keys lowercase as in API Gateway #3117

Closed
wants to merge 3 commits into from

Conversation

mastazi
Copy link

@mastazi mastazi commented Jul 26, 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 mastazi changed the title made dictionary keys lowercase as in API Gateway made headers dictionary keys lowercase as in API Gateway Jul 26, 2021
@jfuss
Copy link
Contributor

jfuss commented Jul 27, 2021

See: #3083 (comment) for more details but .lower() on all headers does not match API Gateway and can break existing customers. Unless we can match exactly what API Gateway does (which doesn't seem possible due to Flask not giving access to raw header data), the solution is to handle this in your function code.

@jfuss jfuss added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. pr/external stage/needs-investigation Requires a deeper investigation labels Jul 27, 2021
@mastazi
Copy link
Author

mastazi commented Jul 29, 2021

Closing PR for the reasons explained here by @jfuss #3083 (comment)

@mastazi mastazi closed this Jul 29, 2021
@mastazi
Copy link
Author

mastazi commented Jul 29, 2021

Thank you @jfuss for looking into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. pr/external stage/needs-investigation Requires a deeper investigation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Headers are received in Camel-Case
2 participants