Cors #86
1 changed files with 17 additions and 0 deletions
|
@ -17,6 +17,9 @@ import (
|
||||||
// ResponseHeaders are returned with each response
|
// ResponseHeaders are returned with each response
|
||||||
var ResponseHeaders map[string]string
|
var ResponseHeaders map[string]string
|
||||||
|
|
||||||
|
// CorsDomains Allowed domains for CORS Policy
|
||||||
|
var CorsDomains []string
|
||||||
|
|
||||||
// Log allows logging of events and errors
|
// Log allows logging of events and errors
|
||||||
var Log = func(*http.Request, *Response, error) {}
|
var Log = func(*http.Request, *Response, error) {}
|
||||||
|
|
||||||
|
@ -78,6 +81,20 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, d := range CorsDomains {
|
||||||
|
if d == r.Header.Get("origin") {
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", d)
|
||||||
|
vary := w.Header().Get("Vary")
|
||||||
|
if vary != "*" {
|
||||||
|
if vary != "" {
|
||||||
|
vary += ", "
|
||||||
|
}
|
||||||
|
vary += "Origin"
|
||||||
|
}
|
||||||
|
w.Header().Set("Vary", vary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Stop here if its a preflighted OPTIONS request
|
// Stop here if its a preflighted OPTIONS request
|
||||||
if r.Method == "OPTIONS" {
|
if r.Method == "OPTIONS" {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue