From f54936467101bb08bbdf7f3d9c341134c06b83c3 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 16 Dec 2015 15:49:04 -0500 Subject: Updating go dependancies --- .../src/github.com/gorilla/websocket/client.go | 13 ++++++-- .../gorilla/websocket/client_server_test.go | 20 +++++++++++- .../github.com/gorilla/websocket/client_test.go | 32 +++++++++++------- .../gorilla/websocket/examples/echo/client.go | 38 ++++++++++++++++++---- 4 files changed, 81 insertions(+), 22 deletions(-) (limited to 'Godeps/_workspace/src/github.com/gorilla/websocket') diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/client.go b/Godeps/_workspace/src/github.com/gorilla/websocket/client.go index 3bf9b2e84..613890603 100644 --- a/Godeps/_workspace/src/github.com/gorilla/websocket/client.go +++ b/Godeps/_workspace/src/github.com/gorilla/websocket/client.go @@ -95,13 +95,20 @@ func parseURL(s string) (*url.URL, error) { return nil, errMalformedURL } - u.Host = s - u.Opaque = "/" + if i := strings.Index(s, "?"); i >= 0 { + u.RawQuery = s[i+1:] + s = s[:i] + } + if i := strings.Index(s, "/"); i >= 0 { - u.Host = s[:i] u.Opaque = s[i:] + s = s[:i] + } else { + u.Opaque = "/" } + u.Host = s + if strings.Contains(u.Host, "@") { // Don't bother parsing user information because user information is // not allowed in websocket URIs. diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/client_server_test.go b/Godeps/_workspace/src/github.com/gorilla/websocket/client_server_test.go index 05a7888fe..c67550e92 100644 --- a/Godeps/_workspace/src/github.com/gorilla/websocket/client_server_test.go +++ b/Godeps/_workspace/src/github.com/gorilla/websocket/client_server_test.go @@ -41,9 +41,16 @@ type cstServer struct { URL string } +const ( + cstPath = "/a/b" + cstRawQuery = "x=y" + cstRequestURI = cstPath + "?" + cstRawQuery +) + func newServer(t *testing.T) *cstServer { var s cstServer s.Server = httptest.NewServer(cstHandler{t}) + s.Server.URL += cstRequestURI s.URL = makeWsProto(s.Server.URL) return &s } @@ -51,11 +58,22 @@ func newServer(t *testing.T) *cstServer { func newTLSServer(t *testing.T) *cstServer { var s cstServer s.Server = httptest.NewTLSServer(cstHandler{t}) + s.Server.URL += cstRequestURI s.URL = makeWsProto(s.Server.URL) return &s } func (t cstHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != cstPath { + t.Logf("path=%v, want %v", r.URL.Path, cstPath) + http.Error(w, "bad path", 400) + return + } + if r.URL.RawQuery != cstRawQuery { + t.Logf("query=%v, want %v", r.URL.RawQuery, cstRawQuery) + http.Error(w, "bad path", 400) + return + } subprotos := Subprotocols(r) if !reflect.DeepEqual(subprotos, cstDialer.Subprotocols) { t.Logf("subprotols=%v, want %v", subprotos, cstDialer.Subprotocols) @@ -188,7 +206,7 @@ func TestDialTLS(t *testing.T) { d := cstDialer d.NetDial = func(network, addr string) (net.Conn, error) { return net.Dial(network, u.Host) } d.TLSClientConfig = &tls.Config{RootCAs: certs} - ws, _, err := d.Dial("wss://example.com/", nil) + ws, _, err := d.Dial("wss://example.com"+cstRequestURI, nil) if err != nil { t.Fatalf("Dial: %v", err) } diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/client_test.go b/Godeps/_workspace/src/github.com/gorilla/websocket/client_test.go index 07a9cb453..7d2b0844f 100644 --- a/Godeps/_workspace/src/github.com/gorilla/websocket/client_test.go +++ b/Godeps/_workspace/src/github.com/gorilla/websocket/client_test.go @@ -11,16 +11,19 @@ import ( ) var parseURLTests = []struct { - s string - u *url.URL + s string + u *url.URL + rui string }{ - {"ws://example.com/", &url.URL{Scheme: "ws", Host: "example.com", Opaque: "/"}}, - {"ws://example.com", &url.URL{Scheme: "ws", Host: "example.com", Opaque: "/"}}, - {"ws://example.com:7777/", &url.URL{Scheme: "ws", Host: "example.com:7777", Opaque: "/"}}, - {"wss://example.com/", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/"}}, - {"wss://example.com/a/b", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/a/b"}}, - {"ss://example.com/a/b", nil}, - {"ws://webmaster@example.com/", nil}, + {"ws://example.com/", &url.URL{Scheme: "ws", Host: "example.com", Opaque: "/"}, "/"}, + {"ws://example.com", &url.URL{Scheme: "ws", Host: "example.com", Opaque: "/"}, "/"}, + {"ws://example.com:7777/", &url.URL{Scheme: "ws", Host: "example.com:7777", Opaque: "/"}, "/"}, + {"wss://example.com/", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/"}, "/"}, + {"wss://example.com/a/b", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/a/b"}, "/a/b"}, + {"ss://example.com/a/b", nil, ""}, + {"ws://webmaster@example.com/", nil, ""}, + {"wss://example.com/a/b?x=y", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/a/b", RawQuery: "x=y"}, "/a/b?x=y"}, + {"wss://example.com?x=y", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/", RawQuery: "x=y"}, "/?x=y"}, } func TestParseURL(t *testing.T) { @@ -30,14 +33,19 @@ func TestParseURL(t *testing.T) { t.Errorf("parseURL(%q) returned error %v", tt.s, err) continue } - if tt.u == nil && err == nil { - t.Errorf("parseURL(%q) did not return error", tt.s) + if tt.u == nil { + if err == nil { + t.Errorf("parseURL(%q) did not return error", tt.s) + } continue } if !reflect.DeepEqual(u, tt.u) { - t.Errorf("parseURL(%q) returned %v, want %v", tt.s, u, tt.u) + t.Errorf("parseURL(%q) = %v, want %v", tt.s, u, tt.u) continue } + if u.RequestURI() != tt.rui { + t.Errorf("parseURL(%q).RequestURI() = %v, want %v", tt.s, u.RequestURI(), tt.rui) + } } } diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/echo/client.go b/Godeps/_workspace/src/github.com/gorilla/websocket/examples/echo/client.go index 45a023175..6578094e7 100644 --- a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/echo/client.go +++ b/Godeps/_workspace/src/github.com/gorilla/websocket/examples/echo/client.go @@ -10,6 +10,8 @@ import ( "flag" "log" "net/url" + "os" + "os/signal" "time" "github.com/gorilla/websocket" @@ -21,6 +23,9 @@ func main() { flag.Parse() log.SetFlags(0) + interrupt := make(chan os.Signal, 1) + signal.Notify(interrupt, os.Interrupt) + u := url.URL{Scheme: "ws", Host: *addr, Path: "/echo"} log.Printf("connecting to %s", u.String()) @@ -30,13 +35,16 @@ func main() { } defer c.Close() + done := make(chan struct{}) + go func() { defer c.Close() + defer close(done) for { _, message, err := c.ReadMessage() if err != nil { log.Println("read:", err) - break + return } log.Printf("recv: %s", message) } @@ -45,11 +53,29 @@ func main() { ticker := time.NewTicker(time.Second) defer ticker.Stop() - for t := range ticker.C { - err := c.WriteMessage(websocket.TextMessage, []byte(t.String())) - if err != nil { - log.Println("write:", err) - break + for { + select { + case t := <-ticker.C: + err := c.WriteMessage(websocket.TextMessage, []byte(t.String())) + if err != nil { + log.Println("write:", err) + return + } + case <-interrupt: + log.Println("interrupt") + // To cleanly close a connection, a client should send a close + // frame and wait for the server to close the connection. + err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) + if err != nil { + log.Println("write close:", err) + return + } + select { + case <-done: + case <-time.After(time.Second): + } + c.Close() + return } } } -- cgit v1.2.3-1-g7c22