-
Notifications
You must be signed in to change notification settings - Fork 186
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Hi @arizz96 please add some test case thanks! |
# Conflicts: # config.go # cors.go
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.
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).
# Conflicts: # config.go # cors.go
@thinkerou thanks for the suggestion and sorry for 1+ year delay! |
Hi @appleboy @thinkerou , this PR is useful. |
@@ -105,8 +106,14 @@ func (cors *cors) validateOrigin(origin string) bool { | |||
if cors.allowAllOrigins { | |||
return true | |||
} | |||
r, _ := regexp.Compile("^\\/(.+)\\/[gimuy]?$") |
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.
Move regexp.Compile
to the top block as a global variable for better performance.
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