Add new option to allow cross origin requests to WS endpoint

This commit is contained in:
Iwasaki Yudai
2017-08-13 15:09:22 +09:00
parent 84ec13ca19
commit 6765efbd61
3 changed files with 15 additions and 2 deletions

View File

@@ -31,7 +31,6 @@ func (server *Server) generateHandleWS(ctx context.Context, cancel context.Cance
if server.options.Once {
success := atomic.CompareAndSwapInt64(once, 0, 1)
if !success {
http.Error(w, "Server is shutting down", http.StatusServiceUnavailable)
return
}
@@ -68,7 +67,7 @@ func (server *Server) generateHandleWS(ctx context.Context, cancel context.Cance
conn, err := server.upgrader.Upgrade(w, r, nil)
if err != nil {
http.Error(w, "Failed to upgrade connection: "+err.Error(), 500)
closeReason = fmt.Sprintf("origin check error: %s", r.Header.Get("Origin"))
return
}
defer conn.Close()