summaryrefslogtreecommitdiffstats
path: root/utils/api.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils/api.go')
-rw-r--r--utils/api.go16
1 files changed, 6 insertions, 10 deletions
diff --git a/utils/api.go b/utils/api.go
index a96e98254..48382d1fe 100644
--- a/utils/api.go
+++ b/utils/api.go
@@ -11,14 +11,12 @@ import (
"github.com/mattermost/mattermost-server/model"
)
-type OriginCheckerProc func(*http.Request) bool
-
-func OriginChecker(r *http.Request) bool {
+func CheckOrigin(r *http.Request, allowedOrigins string) bool {
origin := r.Header.Get("Origin")
- if *Cfg.ServiceSettings.AllowCorsFrom == "*" {
+ if allowedOrigins == "*" {
return true
}
- for _, allowed := range strings.Split(*Cfg.ServiceSettings.AllowCorsFrom, " ") {
+ for _, allowed := range strings.Split(allowedOrigins, " ") {
if allowed == origin {
return true
}
@@ -26,12 +24,10 @@ func OriginChecker(r *http.Request) bool {
return false
}
-func GetOriginChecker(r *http.Request) OriginCheckerProc {
- if len(*Cfg.ServiceSettings.AllowCorsFrom) > 0 {
- return OriginChecker
+func OriginChecker(allowedOrigins string) func(*http.Request) bool {
+ return func(r *http.Request) bool {
+ return CheckOrigin(r, allowedOrigins)
}
-
- return nil
}
func RenderWebError(err *model.AppError, w http.ResponseWriter, r *http.Request) {