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

Allow regexp on AllowOrigins #36

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

arizz96
Copy link

@arizz96 arizz96 commented Jul 8, 2018

This PR enable use of regexp on CORS origin.
It can be useful to allow CORS in different subdomains of a single domain.

Regexp matching requires / at the begin and at the end of regular expression.

For example:
/^https?://(?:.+\.)?mywebsite\.com/g
matches all the subdomains of mywebsite.com, in secure and insecure protocol.

NOTE: in regexp, . matches all characters, so be careful on update it correctly

@codecov-io
Copy link

codecov-io commented Jul 8, 2018

Codecov Report

Merging #36 into master will increase coverage by 0.34%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #36      +/-   ##
==========================================
+ Coverage   93.02%   93.37%   +0.34%     
==========================================
  Files           3        3              
  Lines         172      181       +9     
==========================================
+ Hits          160      169       +9     
  Misses         11       11              
  Partials        1        1
Impacted Files Coverage Δ
config.go 100% <100%> (ø) ⬆️
cors.go 82.6% <100%> (+1.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2a8f489...99f9867. Read the comment docs.

@thinkerou
Copy link
Member

Hi @arizz96 please add some test case thanks!

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Found some fixes!

P.S. share your ideas, feedbacks or issues with us at https://github.com/fixmie/feedback (this message will be removed after the beta stage).

config.go Outdated Show resolved Hide resolved
config.go Outdated Show resolved Hide resolved
config.go Outdated Show resolved Hide resolved
config.go Outdated Show resolved Hide resolved
@arizz96
Copy link
Author

arizz96 commented Oct 30, 2019

@thinkerou thanks for the suggestion and sorry for 1+ year delay!
I added some tests and adapted my code to newest commits.

@Ray0427
Copy link

Ray0427 commented Aug 31, 2021

Hi @appleboy @thinkerou , this PR is useful.
Can you merge this PR?

@@ -105,8 +106,14 @@ func (cors *cors) validateOrigin(origin string) bool {
if cors.allowAllOrigins {
return true
}
r, _ := regexp.Compile("^\\/(.+)\\/[gimuy]?$")
Copy link
Member

Choose a reason for hiding this comment

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

Move regexp.Compile to the top block as a global variable for better performance.

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.

5 participants