Beispiel #1
0
func (l *listener) handshake(c *websocket.Config, _ *http.Request) error {
	pname := l.proto.Name() + ".sp.nanomsg.org"
	for _, p := range c.Protocol {
		if p == pname {
			c.Protocol = append([]string{}, p)
			return nil
		}
	}
	return websocket.ErrBadWebSocketProtocol
}
Beispiel #2
0
// Creates a WebSocket handshake handler
func handshake(config *websocket.Config, rq *http.Request) error {
	ok := false
	for _, proto := range config.Protocol {
		if proto == blipProtocolName {
			ok = true
			break
		}
	}
	if !ok {
		return &websocket.ProtocolError{"I only speak BLIP"}
	}
	config.Protocol = []string{blipProtocolName}
	return nil
}
Beispiel #3
0
// handshake ensures the provided user protocol matches one of the allowed protocols. It returns
// no error if no protocol is specified.
func handshake(config *websocket.Config, req *http.Request, allowed []string) error {
	protocols := config.Protocol
	if len(protocols) == 0 {
		return nil
	}
	for _, protocol := range protocols {
		for _, allow := range allowed {
			if allow == protocol {
				config.Protocol = []string{protocol}
				return nil
			}
		}
	}
	return fmt.Errorf("requested protocol(s) are not supported: %v; supports %v", config.Protocol, allowed)
}
Beispiel #4
0
func bootHandshake(config *websocket.Config, r *http.Request) error {
	p := Responder{nil, r, time.Now()}

	authToken := p.CheckAuthToken()
	if authToken == nil || authToken.Dest == "" || authToken.Retry != "" {
		p.errorLog(http.StatusForbidden, "auth token invalid")
		return fmt.Errorf("auth token invalid")
	}

	config.Protocol = []string{"binary"}

	r.Header.Set("X-Server-IP", authToken.Dest)
	r.Header.Set("Access-Control-Allow-Origin", "*")
	r.Header.Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE")

	p.accessLog(http.StatusSwitchingProtocols)

	return nil
}