fmt.Fprintf(buf, "Sec-WebSocket-Version: %s\r\n", SupportedProtocolVersion)
buf.WriteString("\r\n")
buf.WriteString(err.Error())
+ buf.Flush()
return
}
if err != nil {
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)
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)
}
}