diff options
Diffstat (limited to 'src/pkg/websocket/server.go')
-rw-r--r-- | src/pkg/websocket/server.go | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/pkg/websocket/server.go b/src/pkg/websocket/server.go index e2d8cecbb..bf80f6cc0 100644 --- a/src/pkg/websocket/server.go +++ b/src/pkg/websocket/server.go @@ -5,8 +5,8 @@ package websocket import ( - "http"; - "io"; + "http" + "io" ) // Handler is a interface that use a WebSocket. @@ -39,35 +39,35 @@ func (f Handler) ServeHTTP(c *http.Conn, req *http.Request) { if req.Method != "GET" || req.Proto != "HTTP/1.1" || req.Header["Upgrade"] != "WebSocket" || req.Header["Connection"] != "Upgrade" { - c.WriteHeader(http.StatusNotFound); - io.WriteString(c, "must use websocket to connect here"); - return; + c.WriteHeader(http.StatusNotFound) + io.WriteString(c, "must use websocket to connect here") + return } - rwc, buf, err := c.Hijack(); + rwc, buf, err := c.Hijack() if err != nil { - panic("Hijack failed: ", err.String()); - return; + panic("Hijack failed: ", err.String()) + return } - defer rwc.Close(); - origin := req.Header["Origin"]; - location := "ws://" + req.Host + req.URL.Path; + defer rwc.Close() + origin := req.Header["Origin"] + location := "ws://" + req.Host + req.URL.Path // TODO(ukai): verify origin,location,protocol. - buf.WriteString("HTTP/1.1 101 Web Socket Protocol Handshake\r\n"); - buf.WriteString("Upgrade: WebSocket\r\n"); - buf.WriteString("Connection: Upgrade\r\n"); - buf.WriteString("WebSocket-Origin: " + origin + "\r\n"); - buf.WriteString("WebSocket-Location: " + location + "\r\n"); - protocol := ""; + buf.WriteString("HTTP/1.1 101 Web Socket Protocol Handshake\r\n") + buf.WriteString("Upgrade: WebSocket\r\n") + buf.WriteString("Connection: Upgrade\r\n") + buf.WriteString("WebSocket-Origin: " + origin + "\r\n") + buf.WriteString("WebSocket-Location: " + location + "\r\n") + protocol := "" // canonical header key of WebSocket-Protocol. if protocol, found := req.Header["Websocket-Protocol"]; found { buf.WriteString("WebSocket-Protocol: " + protocol + "\r\n") } - buf.WriteString("\r\n"); + buf.WriteString("\r\n") if err := buf.Flush(); err != nil { return } - ws := newConn(origin, location, protocol, buf, rwc); - f(ws); + ws := newConn(origin, location, protocol, buf, rwc) + f(ws) } |