func allowAnyOriginHandshake(cfg *websocket.Config, req *http.Request) error { var err error cfg.Origin, err = websocket.Origin(cfg, req) cfg.Header = make(http.Header) cfg.Header.Set("Access-Control-Allow-Origin", "*") printf("allowAnyOriginHandshake err: %v", err) return err }
func (server *Server) Handshake(config *ws.Config, request *http.Request) (err error) { for _, protocol := range config.Protocol { if protocol == "cscn" { config.Protocol = []string{protocol} return nil } } return ws.ErrBadWebSocketProtocol }
func checkWAMPHandshake(config *websocket.Config, req *http.Request) error { for _, protocol := range config.Protocol { if protocol == "wamp" { config.Protocol = []string{protocol} return nil } } return websocket.ErrBadWebSocketProtocol }
func (c *WebsocketClient) dialTimeout(config *websocket.Config, timeout uint) (ws *websocket.Conn, err error) { c.logger.Debug("ConnectOnce:websocket.DialConfig:call") defer c.logger.Debug("ConnectOnce:websocket.DialConfig:return") // websocket.Dial() does not handle timeouts, so we use lower-level net package // to create connection with timeout, then create ws client with the net connection. if config.Location == nil { return nil, websocket.ErrBadWebSocketLocation } if config.Origin == nil { return nil, websocket.ErrBadWebSocketOrigin } var conn net.Conn switch config.Location.Scheme { case "ws": conn, err = net.DialTimeout("tcp", config.Location.Host, time.Duration(timeout)*time.Second) case "wss": dialer := &net.Dialer{ Timeout: time.Duration(timeout) * time.Second, } if config.Location.Host == "localhost:8443" { // Test uses mock ws server which uses self-signed cert which causes Go to throw // an error like "x509: certificate signed by unknown authority". This disables // the cert verification for testing. config.TlsConfig = &tls.Config{ InsecureSkipVerify: true, } } conn, err = tls.DialWithDialer(dialer, "tcp", config.Location.Host, config.TlsConfig) default: err = websocket.ErrBadScheme } if err != nil { return nil, &websocket.DialError{config, err} } ws, err = websocket.NewClient(config, conn) if err != nil { return nil, err } return ws, nil }