Skip to content

Commit

Permalink
fixes #8168 by appending elements on match, instead of removing
Browse files Browse the repository at this point in the history
  • Loading branch information
L1ghtman2k committed Jan 25, 2022
1 parent 922e27f commit 94870b8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/ingress/annotations/cors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,18 @@ func (c cors) Parse(ing *networking.Ingress) (interface{}, error) {

unparsedOrigins, err := parser.GetStringAnnotation("cors-allow-origin", ing)
if err == nil {
config.CorsAllowOrigin = strings.Split(unparsedOrigins, ",")
for i, origin := range config.CorsAllowOrigin {
origins := strings.Split(unparsedOrigins, ",")
for _, origin := range origins {
origin = strings.TrimSpace(origin)
if origin == "*" {
config.CorsAllowOrigin = []string{"*"}
break
}
if !corsOriginRegex.MatchString(origin) {

if corsOriginRegex.MatchString(origin) {
config.CorsAllowOrigin = append(config.CorsAllowOrigin, origin)
} else {
klog.Errorf("Error parsing cors-allow-origin parameters. Supplied incorrect origin: %s. Skipping.", origin)
config.CorsAllowOrigin = append(config.CorsAllowOrigin[:i], config.CorsAllowOrigin[i+1:]...)
}
klog.Infof("Current config.corsAllowOrigin %v", config.CorsAllowOrigin)
}
Expand Down

0 comments on commit 94870b8

Please sign in to comment.