Skip to content
Snippets Groups Projects
Commit 030fa427 authored by ale's avatar ale
Browse files

Try to handle CORS preflight requests

parent 5c706f7d
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,16 @@ func NewCollector(sink Sink, handlers ...Handler) *Collector { ...@@ -33,7 +33,16 @@ func NewCollector(sink Sink, handlers ...Handler) *Collector {
} }
func (c *Collector) ServeHTTP(w http.ResponseWriter, req *http.Request) { func (c *Collector) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if req.Method != http.MethodPost { switch req.Method {
case http.MethodPost:
case http.MethodOptions:
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST")
w.Header().Set("Access-Control-Allow-Headers", "content-type")
w.Header().Set("Access-Control-Max-Age", "86400")
w.WriteHeader(http.StatusNoContent)
return
default:
http.Error(w, "Bad method", http.StatusMethodNotAllowed) http.Error(w, "Bad method", http.StatusMethodNotAllowed)
return return
} }
...@@ -56,7 +65,7 @@ hloop: ...@@ -56,7 +65,7 @@ hloop:
case ErrNoMatch: case ErrNoMatch:
continue continue
case nil: case nil:
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusOK)
break hloop break hloop
default: default:
log.Printf("error parsing report: %v", err) log.Printf("error parsing report: %v", err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment