Skip to content

Commit

Permalink
Merge pull request #41 from BugFixes/update-cors-wildcard-logic
Browse files Browse the repository at this point in the history
feat: Add wildcardEnabled method in CORS middleware
  • Loading branch information
Keloran authored May 2, 2024
2 parents 594adc9 + c6106c8 commit 4cd41b1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions middleware/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ func (s *System) getAllowedMethods() string {
return strings.Join(s.AllowedMethods, ", ")
}

func (s *System) wildcardEnabled() bool {
for _, origin := range s.AllowedOrigins {
if origin == "*" {
return true
}
}

return false
}


func (s *System) CORS(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
originalOrigin := r.Header.Get("Origin")

isAllowed := false
isAllowed := s.wildcardEnabled()
for _, origin := range s.AllowedOrigins {
if origin == originalOrigin {
isAllowed = true
Expand All @@ -63,4 +73,4 @@ func (s *System) CORS(next http.Handler) http.Handler {

next.ServeHTTP(w, r)
})
}
}

0 comments on commit 4cd41b1

Please sign in to comment.