-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
HttpApi: wrong capitalisation of properties in the headers object - not asking for headers to be case sensitive #3083
Comments
This is true for Java rapid runtime as well, which makes the development pain, unfortunately. |
Please see previous issue about this: #1860 (comment) This is known difference and something we are not looking to address. Headers are case insensitive and should be handled in the function code. This is also being caused by Flask (what we are using locally to build the service). #1860 (comment) has more info and links to other issues explain it deeper. Closing as won't fix. |
|
Hi @jfuss thank you for your comment and sorry for inadvertently opening a duplicate (I had searched for it but couldn't find #1860 the other day). Just one note though: here you said:
I have to disagree on this one, if the SAM docs tell me that headers are case insensitive, my initial instinct when reading that, is that I'm not going to worry about normalising capitalisation (which is what I ended up doing), because "headers are case-insensitive" sounds like the simulator and the production env would normalise headers to a consistent case, which is not what's happening (SAM headers are always uppercase, API Gateway headers are always lowercase). So, if this inconsistency is not easily fixable, I think the documentation should be updated to let users know that while headers are case-insensitive, they have different case in SAM compared to API Gateway. Is it possible to file an issue related to the AWS SAM docs? Do you know if there is a repo for that? (Edit: there is one it is here https://github.com/awsdocs/aws-sam-developer-guide) |
One more thing @jfuss I want to clarify: reading your comments in #1860 it seems that you are under the impression that users were asking for the headers dictionary to be case-sensitive. This is not what people are asking. You see, API Gateway also makes headers case-insensitive. In API Gateway, both raw headers But in SAM, both of those raw headers would result in What people are asking is for the dictionary to have lowercase properties, so it matches API Gateway. We are not asking for the headers to be case sensitive. The fix would just be to take the
|
Update: submitted PR #3114 |
This will hardly ever be accepted do to the breakage it brings to the users. I'm really sorry your situation, cause I was in the same. You would have to lowercase all the headers from event in your code unfortunately. |
@FieryCod Yes it will bring disruption to some users, however I expect most users are jus converting to lowercase and in that instance, nothing will break. The only instance in which it will break is if users are using if-else check, and retrieve capitalised headers if they are in localhost. |
updated: closed previous pr and reopened as #3117 due to previous PR having issues related to my linter. |
@mastazi We cannot just API Gateway does not document how they determine casing, so whatever we do is going to be heuristics. Headers are case-insensitive and therefore you cannot guarantee how API Gateway will process them. As @FieryCod mentioned, this change will break customers. A function that runs today, will break existing customers. We are willing to accept changes like this but they will need to match API Gateway. Just lowering all headers doesn't match API Gateway and will break customers. If your willing to go down a huge testing flow and add all the heuristics to make this SAM match API Gateway, we can look at that. However, we have done this in the past, and Flask does not have a way to get the raw requests. More details: #1860 (comment) I will comment the same on the PR but currently, I don't think we can accept just |
Thank you @jfuss I missed that comment about Authorization, now I understand what you meant in your comment in #1860 where you said that API Gateway does not document how they do it. Thanks for correcting my wrong assumption, closing #3117
I'm still getting used to the codebase, if I get to a point where I feel ready for that, I will try.
Yes, I see what you mean, however there is a (remote) possibility that the rules that API Gateway is using, could be re-implemented without accessing raw headers, however we don't know that yet. |
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 GatewayI have this function:
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 inevent.headers.Myheader
- note thatMyheader
is capitalised. But after deployment, API Gateway will store the value inevent.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):Steps to reproduce:
event.headers
, see code snippet below.sam local start-api
Foo: bar, Baz: bar
.Observed result:
In the response, you will see those headers will be capitalised:
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:
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: SAM CLI, version 1.23.0The text was updated successfully, but these errors were encountered: