(p []byte)
| 252 | } |
| 253 | |
| 254 | func parseClosePayload(p []byte) (CloseError, error) { |
| 255 | if len(p) == 0 { |
| 256 | return CloseError{ |
| 257 | Code: StatusNoStatusRcvd, |
| 258 | }, nil |
| 259 | } |
| 260 | |
| 261 | if len(p) < 2 { |
| 262 | return CloseError{}, fmt.Errorf("close payload %q too small, cannot even contain the 2 byte status code", p) |
| 263 | } |
| 264 | |
| 265 | ce := CloseError{ |
| 266 | Code: StatusCode(binary.BigEndian.Uint16(p)), |
| 267 | Reason: string(p[2:]), |
| 268 | } |
| 269 | |
| 270 | if !validWireCloseCode(ce.Code) { |
| 271 | return CloseError{}, fmt.Errorf("invalid status code %v", ce.Code) |
| 272 | } |
| 273 | |
| 274 | return ce, nil |
| 275 | } |
| 276 | |
| 277 | // See http://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number |
| 278 | // and https://tools.ietf.org/html/rfc6455#section-7.4.1 |
searching dependent graphs…