(fh []byte, compressed bool, frameType wsOpCode, l int)
| 560 | } |
| 561 | |
| 562 | func wsFillFrameHeader(fh []byte, compressed bool, frameType wsOpCode, l int) (int, []byte) { |
| 563 | var n int |
| 564 | b := byte(frameType) |
| 565 | b |= wsFinalBit |
| 566 | if compressed { |
| 567 | b |= wsRsv1Bit |
| 568 | } |
| 569 | b1 := byte(wsMaskBit) |
| 570 | switch { |
| 571 | case l <= 125: |
| 572 | n = 2 |
| 573 | fh[0] = b |
| 574 | fh[1] = b1 | byte(l) |
| 575 | case l < 65536: |
| 576 | n = 4 |
| 577 | fh[0] = b |
| 578 | fh[1] = b1 | 126 |
| 579 | binary.BigEndian.PutUint16(fh[2:], uint16(l)) |
| 580 | default: |
| 581 | n = 10 |
| 582 | fh[0] = b |
| 583 | fh[1] = b1 | 127 |
| 584 | binary.BigEndian.PutUint64(fh[2:], uint64(l)) |
| 585 | } |
| 586 | var key []byte |
| 587 | var keyBuf [4]byte |
| 588 | if _, err := io.ReadFull(rand.Reader, keyBuf[:4]); err != nil { |
| 589 | kv := mrand.Int31() |
| 590 | binary.LittleEndian.PutUint32(keyBuf[:4], uint32(kv)) |
| 591 | } |
| 592 | copy(fh[n:], keyBuf[:4]) |
| 593 | key = fh[n : n+4] |
| 594 | n += 4 |
| 595 | return n, key |
| 596 | } |
| 597 | |
| 598 | func (nc *Conn) wsInitHandshake(u *url.URL) error { |
| 599 | compress := nc.Opts.Compression |
no outgoing calls
no test coverage detected