Open digitaldjango opened 7 years ago
@Speedrockracer Can you post your settings file? Do you happen to have CORS enabled? Doe the following setting make a difference:
"cors": {"allowed_headers": ["content-type", "Content-Type", "X-Amz-Date", "Authorization", "X-Api-Key", X-Amz-Security-Token"]}
I had cors enabled and tried your suggestion but it didn't help.. Also note that the header in question is visible in the zappa tail call leading me to believe that it is passed correctly to the lambda.
I tried with a new config without cors and minimal settings but the problem still remains. curl:
curl -i -X POST -H "content-type: application/x-www-form-urlencoded" -d "password=tester&title=Django%E2%80%99s%20MacBook%20Pro&type=2&username=tester" https://1wbn5kovxh.execute-api.eu-west-1.amazonaws.com/temp/auth/
Zappa settings:
"temp": {
"app_function": "app.__init__.app",
"aws_region": "eu-west-1",
"profile_name": "default",
"s3_bucket": "zappa-pe8osfm9",
"binary_support": false,
"memory_size": 1536,
"extra_permissions": [
{
"Effect": "Allow",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::images.urlyapp.io/media/*"
},
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::images.urlyapp.io/uploads/*"
}
],
"vpc_config": {
"SubnetIds": [*********],
"SecurityGroupIds": [ ********]
}
}
So I checked the source of zappa and it seems the wsgi.py file has some code that should do it. It looks like it should work. I tried some stuff but don't have much experience with zappa or python in general so I didn't get far debugging. Any help would be appriciated :)
Hey Speed - is your problem that it's changing? Or that it isn't getting passed through at all? Should application be able to handle any case?
According to the logs the header is coming in to zappa (first line of the log posted above contains json with the headers among other things.). When the header is "Content-Type" flask receives it but when it is "content-type" it's not passed trough to flask at all. The code at around line 85 of wsgi.py should convert the header to "Content-Type" I think but maybe something goes wrong there.
This bit me as well. I think the issue is here. The headers
dictionary is modified while it is being iterated over. This causes some unexpected behavior. In particular, some of the headers don't get canonicalized. What makes it even trickier is that it's not deterministic as to which headers get skipped. It depends on the contents of the headers
dictionary itself. You can read more about the dangers of modifying dictionaries while iterating over them here.
If the Content-Type
header does not get canonicalized then it fails this test and instead of being placed into environ['CONTENT_TYPE']
it gets placed into environ['HTTP_CONTENT_TYPE']
down here where it may go unrecognized by your wsgi app.
Changing the canonicalization code to this seems to fix it for me: https://github.com/ajw0100/Zappa/commit/90acabd8117e15e91de066ca85ff0315f1a98f63
If this works for others I can submit a PR.
I am currently using a temp fix to make my project run.
json = request.get_json(force=True)
I'll have some time to test your commit somewhere next week!
Tested patch ajw0100/Zappa@90acabd and it fixes the content-type issue #1188. Tested directly and with python-github-webhook where the content-type bug shows for POST events. Can we get this merged? Do we need a separate PR?
I ran into the same issue (in combination with Apistar). I could not find any information about pending releases for Zappa, is there already one planned that contains the fix by @ajw0100?
Was this issue fixed?
I am running the latest version of Zappa (0.48.2), and Content-Type header is not being received. Any tips what I can do?
Edit: Ah, in wsgi.py you need to send ["POST", "PUT", "PATCH", "DELETE"] for content-type to be set.
Edit: Figured it out if the header is "content-type" zappa doesn't pass it to flask. "Content-Type" gets passed. According to the specs headers should be case insensetive.
Context
Request with lowercase content-type header
As you can see the content type header is printed in zappa event but not present in the headers.
Here are the logs for a "seemingly" same request made with a Content-Type header
I tried:
Expected Behavior
The content type header should be available and the request body parsed.
Actual Behavior
Content type header is None and the request body is not parsed.
Steps to Reproduce
Works: curl -i -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "password=tester&title=Django%E2%80%99s%20MacBook%20Pro&type=2&username=tester" https://api.urlyapp.io/auth/ Doesn't work: curl -i -X POST -H "content-type: application/x-www-form-urlencoded" -d "password=tester&title=Django%E2%80%99s%20MacBook%20Pro&type=2&username=tester" https://api.urlyapp.io/auth/
Your Environment