Allow cross-origin requests for example

For the sake of testing the websocket server, accepting cross-origin requests is useful - to allow usage of things like http://www.websocket.org/echo.html
This commit is contained in:
William Dunne 2015-11-01 16:40:20 +00:00
parent 527637c0f3
commit 773808209f
1 changed files with 5 additions and 1 deletions

View File

@ -16,7 +16,11 @@ import (
var addr = flag.String("addr", "localhost:8081", "http service address")
var upgrader = websocket.Upgrader{} // use default options
var upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return true
},
} // use default options, except origin. Allows cross-origin requests for testing.
func echo(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {