-
Notifications
You must be signed in to change notification settings - Fork 170
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
Convert existing CORS module into a policy #487
Conversation
The functionality is exactly the same.
apicast/src/policy/cors.lua
Outdated
|
||
if not origin then return end | ||
|
||
ngx.header['Access-Control-Allow-Headers'] = ngx.var.http_access_control_request_headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about these 2. Should we return the headers and methods that apicast supports? Or should we just accept everything (like we do now) because we don't know that the upstream api accepts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this module should accept a configuration that would whitelist what HTTP methods / Headers are supported. And possibly what origins too and if to pass credentials or not.
But until we have that configuration we can't do much other than just allow all. And even with the configuration there should be a way to configure it as accept all that browser requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. We can use the "configuration" field of a policy to pass this information for now: https://github.com/3scale/apicast/blob/master/apicast/src/configuration.lua#L167
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. That sounds good! Forgot it is there :)
5e75c0b
to
768ad17
Compare
apicast/src/policy/cors.lua
Outdated
end | ||
|
||
local function set_access_control_allow_headers(allow_headers) | ||
local value = allow_headers and concat(allow_headers, ',') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be possible to assign a table to the header and nginx should take care of the serialization. That could simplify the code a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I didn't know that.
Changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very nice! 🥇 👍
apicast/src/policy/cors.lua
Outdated
|
||
local concat = table.concat | ||
|
||
local policy = require('policy') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will produce a deprecation warning once #486 is merged. No action needed here, but that PR is going to have to fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect 👍
Closes #484
This PR simply converts the existing CORS module into a policy without changing its behavior.
I've also added integration tests based on the new
TestAPIcastBlackbox
module.@mikz I have some questions about the current behavior of this CORS module. Please check my comments and let me know what you think.