Skip to content

Commit

Permalink
Origin wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
cv65kr committed Nov 4, 2023
1 parent dbef1f6 commit e2d7167
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ type Configurer interface {
// Plugin serves headers files. Potentially convert into middleware?
type Plugin struct {
// server configuration (location, forbidden files and etc)
cfg *Config
prop propagation.TextMapPropagator
cors *cors.Cors
cfg *Config
prop propagation.TextMapPropagator
cors *cors.Cors
allowedOriginRegex *regexp.Regexp
}

// Init must return configure service and return true if service hasStatus enabled. Must return error in case of
Expand Down Expand Up @@ -73,8 +74,13 @@ func (p *Plugin) Init(cfg Configurer) error {

// if this option is set, the content of `AllowedOrigins` is ignored
if p.cfg.CORS.AllowedOriginWildcard != "" {
var err error
p.allowedOriginRegex, err = regexp.Compile(p.cfg.CORS.AllowedOriginWildcard)
if err != nil {
return errors.E(op, err)
}
opts.AllowOriginFunc = func(origin string) bool {
return regexp.MustCompile(p.cfg.CORS.AllowedOriginWildcard).MatchString(origin)
return p.allowedOriginRegex.MatchString(origin)
}
}

Expand Down

0 comments on commit e2d7167

Please sign in to comment.