-
-
Notifications
You must be signed in to change notification settings - Fork 295
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
Add support for wildcard '*' in cors domains #563
Conversation
Hi, @Sagebati , Thank you for your mr. Would you please add some testcase and fix the CI? |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Seems like the CI passes |
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.
Just a suggestion: consider to use a wildmatch crate
I didn't knew this crate, I could rewrite the feature to use it. The change implies that we will have a |
What do you think if it could be better like below? @Sagebati pub struct Cors {
allow_credentials: bool,
allow_origins: HashSet<HeaderValue>,
allow_origins_wildcard: Vec<WildMatch>, //////// <<<<<<<<<
allow_origins_fn: Option<Arc<dyn Fn(&str) -> bool + Send + Sync>>,
allow_headers: HashSet<HeaderName>,
allow_methods: HashSet<Method>,
expose_headers: HashSet<HeaderName>,
max_age: i32,
}
impl Cors {
fn allow_origin_to_regex(mut self, wildcard: impl AsRef<str>) -> Self {
self.allow_origins_wildcard.push(WildMatch::new(wildcard));
self
}
} |
Added the functionality to specify wildcard '*' in cors domains
I rewrote the PR to use the wildmatch crate, let me know if there is anything to review |
Could you help to add a test case? 🙂 @Sagebati |
Thanks! @Sagebati 🙂 |
Hi !
This new feature is especially useful for applications that utilize multiple subdomains, as it eliminates the need to manually configure CORS for each subdomain. By simply adding the wildcard (*) to your CORS configuration, you can enable cross-domain requests for all subdomains of a given domain. I replaced the
HashSet::contains
search with a Regex containing all the domains (example:https://regex101.com/r/ZEhBy4/2). I'm aware ofthe allow_origin_fn
, but in opinion this is ergonomic. The PR is almost ready to be merged only need a review of theunwrap
used.Any feedback is welcome.