Skip to content

x/net/websocket: No way to manage connection outside of handler #5959

@lukescott

Description

@lukescott
Currently there is no way to get a websocket.Conn object without leaving the handler, or
without having a handler at all. I need to wrap the websocket.Conn object for another
library, but not without maintaing a blocked go routine.

I suggest adding this method:

func (s Server) Upgrade(w http.ResponseWriter, req *http.Request) (conn *Conn, err
error) {
    var rwc net.Conn
    var buf *bufio.ReadWriter
    if rwc, buf, err = w.(http.Hijacker).Hijack(); err != nil {
        return nil, err
    }
    conn, err = newServerConn(rwc, buf, req, &s.Config, s.Handshake);
    return
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions