(opts *DialOptions, copts *compressionOptions, secWebSocketKey string, resp *http.Response)
| 240 | } |
| 241 | |
| 242 | func 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 | |
| 270 | func verifySubprotocol(subprotos []string, resp *http.Response) error { |
| 271 | proto := resp.Header.Get("Sec-WebSocket-Protocol") |
no test coverage detected
searching dependent graphs…