MCPcopy
hub / github.com/coder/websocket / verifyServerResponse

Function verifyServerResponse

dial.go:242–268  ·  view source on GitHub ↗
(opts *DialOptions, copts *compressionOptions, secWebSocketKey string, resp *http.Response)

Source from the content-addressed store, hash-verified

240}
241
242func verifyServerResponse(opts *DialOptions, copts *compressionOptions, secWebSocketKey string, resp *http.Response) (*compressionOptions, error) {
243 if resp.StatusCode != http.StatusSwitchingProtocols {
244 return nil, fmt.Errorf("expected handshake response status code %v but got %v", http.StatusSwitchingProtocols, resp.StatusCode)
245 }
246
247 if !headerContainsTokenIgnoreCase(resp.Header, "Connection", "Upgrade") {
248 return nil, fmt.Errorf("WebSocket protocol violation: Connection header %q does not contain Upgrade", resp.Header.Get("Connection"))
249 }
250
251 if !headerContainsTokenIgnoreCase(resp.Header, "Upgrade", "WebSocket") {
252 return nil, fmt.Errorf("WebSocket protocol violation: Upgrade header %q does not contain websocket", resp.Header.Get("Upgrade"))
253 }
254
255 if resp.Header.Get("Sec-WebSocket-Accept") != secWebSocketAccept(secWebSocketKey) {
256 return nil, fmt.Errorf("WebSocket protocol violation: invalid Sec-WebSocket-Accept %q, key %q",
257 resp.Header.Get("Sec-WebSocket-Accept"),
258 secWebSocketKey,
259 )
260 }
261
262 err := verifySubprotocol(opts.Subprotocols, resp)
263 if err != nil {
264 return nil, err
265 }
266
267 return verifyServerExtensions(copts, resp.Header)
268}
269
270func verifySubprotocol(subprotos []string, resp *http.Response) error {
271 proto := resp.Header.Get("Sec-WebSocket-Protocol")

Callers 1

dialFunction · 0.85

Calls 4

secWebSocketAcceptFunction · 0.85
verifySubprotocolFunction · 0.85
verifyServerExtensionsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…