diff options
Diffstat (limited to 'libgo/go/websocket')
-rw-r--r-- | libgo/go/websocket/client.go | 2 | ||||
-rw-r--r-- | libgo/go/websocket/hixie.go | 6 | ||||
-rw-r--r-- | libgo/go/websocket/hixie_test.go | 4 | ||||
-rw-r--r-- | libgo/go/websocket/hybi.go | 4 | ||||
-rw-r--r-- | libgo/go/websocket/hybi_test.go | 4 | ||||
-rw-r--r-- | libgo/go/websocket/server.go | 8 | ||||
-rw-r--r-- | libgo/go/websocket/websocket.go | 6 | ||||
-rw-r--r-- | libgo/go/websocket/websocket_test.go | 25 |
8 files changed, 32 insertions, 27 deletions
diff --git a/libgo/go/websocket/client.go b/libgo/go/websocket/client.go index 3da39a0ce47..5dfd824e6e5 100644 --- a/libgo/go/websocket/client.go +++ b/libgo/go/websocket/client.go @@ -9,7 +9,7 @@ import ( "crypto/tls" "io" "net" - "url" + "net/url" ) // DialError is an error that occurs while dialling a websocket server. diff --git a/libgo/go/websocket/hixie.go b/libgo/go/websocket/hixie.go index 63eebc95020..4d5360ff4b9 100644 --- a/libgo/go/websocket/hixie.go +++ b/libgo/go/websocket/hixie.go @@ -13,13 +13,13 @@ import ( "crypto/md5" "encoding/binary" "fmt" - "http" "io" "io/ioutil" - "rand" + "math/rand" + "net/http" + "net/url" "strconv" "strings" - "url" ) // An aray of characters to be randomly inserted to construct Sec-WebSocket-Key diff --git a/libgo/go/websocket/hixie_test.go b/libgo/go/websocket/hixie_test.go index 40cb53f4ea5..bf537c01b73 100644 --- a/libgo/go/websocket/hixie_test.go +++ b/libgo/go/websocket/hixie_test.go @@ -8,11 +8,11 @@ import ( "bufio" "bytes" "fmt" - "http" "io" + "net/http" + "net/url" "strings" "testing" - "url" ) // Test the getChallengeResponse function with values from section diff --git a/libgo/go/websocket/hybi.go b/libgo/go/websocket/hybi.go index d3d4258e981..b17d9470bbc 100644 --- a/libgo/go/websocket/hybi.go +++ b/libgo/go/websocket/hybi.go @@ -15,11 +15,11 @@ import ( "encoding/base64" "encoding/binary" "fmt" - "http" "io" "io/ioutil" + "net/http" + "net/url" "strings" - "url" ) const ( diff --git a/libgo/go/websocket/hybi_test.go b/libgo/go/websocket/hybi_test.go index df0f5552653..60375ff32ad 100644 --- a/libgo/go/websocket/hybi_test.go +++ b/libgo/go/websocket/hybi_test.go @@ -8,11 +8,11 @@ import ( "bufio" "bytes" "fmt" - "http" "io" + "net/http" + "net/url" "strings" "testing" - "url" ) // Test the getNonceAccept function with values in diff --git a/libgo/go/websocket/server.go b/libgo/go/websocket/server.go index 9420c47191d..57dc4fd1dff 100644 --- a/libgo/go/websocket/server.go +++ b/libgo/go/websocket/server.go @@ -7,8 +7,8 @@ package websocket import ( "bufio" "fmt" - "http" "io" + "net/http" ) func newServerConn(rwc io.ReadWriteCloser, buf *bufio.ReadWriter, req *http.Request) (conn *Conn, err error) { @@ -20,6 +20,7 @@ func newServerConn(rwc io.ReadWriteCloser, buf *bufio.ReadWriter, req *http.Requ fmt.Fprintf(buf, "Sec-WebSocket-Version: %s\r\n", SupportedProtocolVersion) buf.WriteString("\r\n") buf.WriteString(err.Error()) + buf.Flush() return } if err != nil { @@ -34,12 +35,17 @@ func newServerConn(rwc io.ReadWriteCloser, buf *bufio.ReadWriter, req *http.Requ fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, http.StatusText(code)) buf.WriteString("\r\n") buf.WriteString(err.Error()) + buf.Flush() return } config.Protocol = nil err = hs.AcceptHandshake(buf.Writer) if err != nil { + code = http.StatusBadRequest + fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, http.StatusText(code)) + buf.WriteString("\r\n") + buf.Flush() return } conn = hs.NewServerConn(buf, rwc, req) diff --git a/libgo/go/websocket/websocket.go b/libgo/go/websocket/websocket.go index 9732ae11735..1e4036ce391 100644 --- a/libgo/go/websocket/websocket.go +++ b/libgo/go/websocket/websocket.go @@ -9,14 +9,14 @@ package websocket import ( "bufio" "crypto/tls" - "http" + "encoding/json" "io" "io/ioutil" - "json" "net" + "net/http" + "net/url" "os" "sync" - "url" ) const ( diff --git a/libgo/go/websocket/websocket_test.go b/libgo/go/websocket/websocket_test.go index 69b5335cfa9..f41c355fac2 100644 --- a/libgo/go/websocket/websocket_test.go +++ b/libgo/go/websocket/websocket_test.go @@ -7,15 +7,15 @@ package websocket import ( "bytes" "fmt" - "http" - "http/httptest" "io" "log" "net" + "net/http" + "net/http/httptest" + "net/url" "strings" "sync" "testing" - "url" ) var serverAddr string @@ -200,20 +200,19 @@ func TestHTTP(t *testing.T) { once.Do(startServer) // If the client did not send a handshake that matches the protocol - // specification, the server should abort the WebSocket connection. - _, err := http.Get(fmt.Sprintf("http://%s/echo", serverAddr)) - if err == nil { - t.Error("Get: unexpected success") + // specification, the server MUST return an HTTP respose with an + // appropriate error code (such as 400 Bad Request) + resp, err := http.Get(fmt.Sprintf("http://%s/echo", serverAddr)) + if err != nil { + t.Errorf("Get: error %#v", err) return } - urlerr, ok := err.(*url.Error) - if !ok { - t.Errorf("Get: not url.Error %#v", err) + if resp == nil { + t.Error("Get: resp is null") return } - if urlerr.Err != io.ErrUnexpectedEOF { - t.Errorf("Get: error %#v", err) - return + if resp.StatusCode != http.StatusBadRequest { + t.Errorf("Get: expected %q got %q", http.StatusBadRequest, resp.StatusCode) } } |