MCPcopy Create free account
hub / github.com/koding/kite / DialWebsocket

Function DialWebsocket

sockjsclient/sockjsclient.go:136–164  ·  view source on GitHub ↗

DialWebsocket establishes a SockJS session over a websocket connection. Requires cfg.Websocket to be a valid client.

(uri string, cfg *config.Config)

Source from the content-addressed store, hash-verified

134//
135// Requires cfg.Websocket to be a valid client.
136func DialWebsocket(uri string, cfg *config.Config) (*WebsocketSession, error) {
137 u, err := url.Parse(uri)
138 if err != nil {
139 return nil, err
140 }
141
142 h := http.Header{
143 "Origin": {u.Scheme + "://" + u.Host},
144 }
145
146 serverID := threeDigits()
147 sessionID := utils.RandomString(20)
148
149 u = makeWebsocketURL(u, serverID, sessionID)
150
151 conn, _, err := cfg.Websocket.Dial(u.String(), h)
152 if err != nil {
153 return nil, err
154 }
155
156 session := NewWebsocketSession(conn)
157 session.id = sessionID
158 session.req = &http.Request{
159 URL: u,
160 Header: h,
161 }
162
163 return session, nil
164}
165
166// ConnectWebsocketSession dials the remote specified in the opts and
167// creates new websocket session.

Callers 1

ConnectWebsocketSessionFunction · 0.85

Calls 5

threeDigitsFunction · 0.85
makeWebsocketURLFunction · 0.85
NewWebsocketSessionFunction · 0.85
DialMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected