diff options
author | Mikio Hara <mikioh.mikioh@gmail.com> | 2014-06-02 21:39:33 +0900 |
---|---|---|
committer | Mikio Hara <mikioh.mikioh@gmail.com> | 2014-06-02 21:39:33 +0900 |
commit | 96cece04e7db82dd9a602f37023c0915b582ac4d (patch) | |
tree | 8c821c54e38d7a69d419dda37e28b3b8a2e685e1 /playground | |
parent | 707c7629cb89ba220eee36bbad8e84832887ebe7 (diff) | |
download | golang-x-tools-96cece04e7db82dd9a602f37023c0915b582ac4d.tar.gz |
go.tools/{cmd/present,playground/socket}: add orighost flag to handle the web origin more flexible
Also fixes the following nits;
- literal IPv6 address handling
- URL host component handling in the case of a wildcard listen
- URL port component handling in the case of no port component in origin
Fixes golang/go#8096.
LGTM=dan.kortschak, adg
R=adg, golang-codereviews, dan.kortschak
CC=golang-codereviews
https://golang.org/cl/102770046
Diffstat (limited to 'playground')
-rw-r--r-- | playground/socket/socket.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/playground/socket/socket.go b/playground/socket/socket.go index 51c2a49ee..4d84cf096 100644 --- a/playground/socket/socket.go +++ b/playground/socket/socket.go @@ -22,6 +22,7 @@ import ( "io" "io/ioutil" "log" + "net" "net/http" "net/url" "os" @@ -84,7 +85,12 @@ func handshake(c *websocket.Config, req *http.Request) error { log.Println("bad websocket origin:", err) return websocket.ErrBadWebSocketOrigin } - ok := c.Origin.Scheme == o.Scheme && c.Origin.Host == o.Host + _, port, err := net.SplitHostPort(c.Origin.Host) + if err != nil { + log.Println("bad websocket origin:", err) + return websocket.ErrBadWebSocketOrigin + } + ok := c.Origin.Scheme == o.Scheme && (c.Origin.Host == o.Host || c.Origin.Host == net.JoinHostPort(o.Host, port)) if !ok { log.Println("bad websocket origin:", o) return websocket.ErrBadWebSocketOrigin |