LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package websocket | 5 package websocket |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "bytes" | 9 "bytes" |
10 "container/vector" | 10 "container/vector" |
11 "crypto/tls" | 11 "crypto/tls" |
12 "fmt" | 12 "fmt" |
13 "http" | 13 "http" |
14 "io" | 14 "io" |
15 "net" | 15 "net" |
16 "os" | 16 "os" |
17 "rand" | 17 "rand" |
18 "strings" | 18 "strings" |
19 ) | 19 ) |
20 | 20 |
21 type ProtocolError struct { | 21 type ProtocolError struct { |
22 ErrorString string | 22 ErrorString string |
23 } | 23 } |
24 | 24 |
25 func (err ProtocolError) String() string { return string(err.ErrorString) } | 25 func (err *ProtocolError) String() string { return string(err.ErrorString) } |
26 | 26 |
27 var ( | 27 var ( |
28 ErrBadScheme = &ProtocolError{"bad scheme"} | 28 ErrBadScheme = &ProtocolError{"bad scheme"} |
29 ErrBadStatus = &ProtocolError{"bad status"} | 29 ErrBadStatus = &ProtocolError{"bad status"} |
30 ErrBadUpgrade = &ProtocolError{"missing or bad upgrade"} | 30 ErrBadUpgrade = &ProtocolError{"missing or bad upgrade"} |
31 ErrBadWebSocketOrigin = &ProtocolError{"missing or bad WebSocket-Origi
n"} | 31 ErrBadWebSocketOrigin = &ProtocolError{"missing or bad WebSocket-Origi
n"} |
32 ErrBadWebSocketLocation = &ProtocolError{"missing or bad WebSocket-Locat
ion"} | 32 ErrBadWebSocketLocation = &ProtocolError{"missing or bad WebSocket-Locat
ion"} |
33 ErrBadWebSocketProtocol = &ProtocolError{"missing or bad WebSocket-Proto
col"} | 33 ErrBadWebSocketProtocol = &ProtocolError{"missing or bad WebSocket-Proto
col"} |
34 ErrChallengeResponse = &ProtocolError{"mismatch challenge/response"} | 34 ErrChallengeResponse = &ProtocolError{"mismatch challenge/response"} |
35 secKeyRandomChars [0x30 - 0x21 + 0x7F - 0x3A]byte | 35 secKeyRandomChars [0x30 - 0x21 + 0x7F - 0x3A]byte |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 return ErrBadWebSocketOrigin | 314 return ErrBadWebSocketOrigin |
315 } | 315 } |
316 if resp.Header.Get("Websocket-Location") != location { | 316 if resp.Header.Get("Websocket-Location") != location { |
317 return ErrBadWebSocketLocation | 317 return ErrBadWebSocketLocation |
318 } | 318 } |
319 if protocol != "" && resp.Header.Get("Websocket-Protocol") != protocol { | 319 if protocol != "" && resp.Header.Get("Websocket-Protocol") != protocol { |
320 return ErrBadWebSocketProtocol | 320 return ErrBadWebSocketProtocol |
321 } | 321 } |
322 return | 322 return |
323 } | 323 } |
LEFT | RIGHT |