1
#pragma once
2

            
3
// NOLINT(namespace-envoy)
4

            
5
// Some sensible limits to protect against excess resource use
6
24
#define WEBSOCKET_HANDSHAKE_MAX_SIZE 4096
7
162
#define WEBSOCKET_CONTROL_FRAME_MAX_SIZE 256
8

            
9
/* Ref. RFC 6455 */
10

            
11
23
#define WEBSOCKET_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
12
/*
13
    0                   1                   2                   3
14
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
15
   +-+-+-+-+-------+-+-------------+-------------------------------+
16
   |F|R|R|R| opcode|M| Payload len |    Extended payload length    |
17
   |I|S|S|S|  (4)  |A|     (7)     |             (16/64)           |
18
   |N|V|V|V|       |S|             |   (if payload len==126/127)   |
19
   | |1|2|3|       |K|             |                               |
20
   +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
21
   |     Extended payload length continued, if payload len == 127  |
22
   + - - - - - - - - - - - - - - - +-------------------------------+
23
   |                               |Masking-key, if MASK set to 1  |
24
   +-------------------------------+-------------------------------+
25
   | Masking-key (continued)       |          Payload Data         |
26
   +-------------------------------- - - - - - - - - - - - - - - - +
27
   :                     Payload Data continued ... :
28
   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
29
   |                     Payload Data continued ... |
30
   +---------------------------------------------------------------+
31
*/
32

            
33
218
#define FIN_MASK 0x80
34
206
#define OPCODE_MASK 0x0F
35
327
#define MASK_MASK 0x80
36
206
#define PAYLOAD_LEN_MASK 0x7F
37

            
38
/*
39
 Opcode:  4 bits
40

            
41
    Defines the interpretation of the "Payload data". If an unknown
42
    opcode is received, the receiving endpoint MUST _Fail the
43
    WebSocket Connection_. The following values are defined.
44

            
45
    *  %x0 denotes a continuation frame
46

            
47
    *  %x1 denotes a text frame
48

            
49
    *  %x2 denotes a binary frame
50

            
51
    *  %x3-7 are reserved for further non-control frames
52

            
53
    *  %x8 denotes a connection close
54

            
55
    *  %x9 denotes a ping
56

            
57
    *  %xA denotes a pong
58

            
59
    *  %xB-F are reserved for further control frames
60
    */
61
#define OPCODE_CONTINUE 0
62
#define OPCODE_TEXT 1
63
58
#define OPCODE_BIN 2
64
246
#define OPCODE_CLOSE 8
65
170
#define OPCODE_PING 9
66
129
#define OPCODE_PONG 10