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

Convert existing CORS module into a policy #487

Merged
merged 4 commits into from
Nov 21, 2017
Merged

Convert existing CORS module into a policy #487

merged 4 commits into from
Nov 21, 2017

Conversation

davidor
Copy link
Contributor

@davidor davidor commented Nov 20, 2017

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.


if not origin then return end

ngx.header['Access-Control-Allow-Headers'] = ngx.var.http_access_control_request_headers
Copy link
Contributor Author

@davidor davidor Nov 20, 2017

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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 :)

@davidor davidor requested a review from mikz November 20, 2017 14:54
@davidor davidor changed the title Convert existing CORS module into a policy [WIP] Convert existing CORS module into a policy Nov 20, 2017
@davidor davidor force-pushed the cors-policy branch 4 times, most recently from 5e75c0b to 768ad17 Compare November 21, 2017 09:46
@davidor davidor changed the title [WIP] Convert existing CORS module into a policy Convert existing CORS module into a policy Nov 21, 2017
end

local function set_access_control_allow_headers(allow_headers)
local value = allow_headers and concat(allow_headers, ',')
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@mikz mikz left a 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! 🥇 👍


local concat = table.concat

local policy = require('policy')
Copy link
Contributor

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.

Copy link
Contributor

@mikz mikz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect 👍

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.

2 participants