-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: set cors allow origins by plugin metadata #6546
feat: set cors allow origins by plugin metadata #6546
Conversation
I haven't edited any docs yet, would like some opinions on the feature and the implementation/tests before moving on |
apisix/plugins/cors.lua
Outdated
if not match_origins(req_origin, allow_origins) then | ||
allow_origins = process_with_allow_origins_by_regex(conf, ctx, req_origin) | ||
end | ||
if not match_origins(req_origin, allow_origins) then |
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.
if not match_origins(req_origin, allow_origins) then | |
if not allow_origins then |
t/plugin/cors3.t
Outdated
} | ||
} | ||
--- request | ||
GET /t |
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.
Let's use this script to simplify the duplicate fields:
#!/usr/bin/env python
# coding: utf-8
# Usage: ./simpify.py $test_filename
import sys
with open(sys.argv[1]) as f:
lines = [l.rstrip() for l in f.readlines()]
newlines = []
for i, l in enumerate(lines):
if ((l == "GET /t" and lines[i-1] == "--- request") or
(l == "[error]" and lines[i-1] == "--- no_error_log")):
newlines = newlines[:-1]
continue
newlines.append(l)
res = "\n".join(newlines)
# print(res)
with open(sys.argv[1], "w") as f:
f.write(res + '\n')
…etadata # Conflicts: # docs/en/latest/plugins/cors.md # docs/zh/latest/plugins/cors.md
apisix/plugins/cors.lua
Outdated
create_multiple_origin_cache, conf) | ||
|
||
if not (cache_key and cache_version) then | ||
cache_key, cache_version = core.lrucache.plugin_ctx_id(ctx) |
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.
plugin_ctx_id
only returns an ID?
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.
😂fixed
apisix/plugins/cors.lua
Outdated
local allow_origins = conf.allow_origins | ||
local function process_with_allow_origins(allow_origins_conf, ctx, req_origin, | ||
cache_key, cache_version) | ||
local allow_origins = allow_origins_conf |
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.
We don't need to declare allow_origins_conf
as local allow_origins
here, just change the allow_origins_conf
-> allow_origins
in parameter list is ok?
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, changed that
Co-authored-by: tzssangglass <[email protected]>
…y_plugin_metadata' into feature/set_cors_allow_origins_by_plugin_metadata
What this PR does / why we need it:
Supports setting allow_origins by plugin metadata in the cors plugin. We usually have many routes sharing the same set of allowed origins, and it's really inconvenient when trying to update the allowed_origins sets (have to do it for all routes). Existing admin objects like services and plugin configs don't exactly solve this issue since the routes may have different configurations for other plugins but share the same allowe_origins.
Pre-submission checklist: