xref: /aosp_15_r20/external/cronet/net/websockets/websocket_handshake_constants.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // A set of common constants that are needed for the WebSocket handshake.
6 // In general, you should prefer using these constants to literal strings,
7 // except in tests.
8 //
9 // These constants cannot be used in files that are compiled on iOS, because
10 // this file is not compiled on iOS.
11 
12 #ifndef NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_CONSTANTS_H_
13 #define NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_CONSTANTS_H_
14 
15 #include <stddef.h>
16 
17 #include "net/base/net_export.h"
18 
19 // This file plases constants inside the ::net::websockets namespace to avoid
20 // risk of collisions with other symbols in libnet.
21 namespace net::websockets {
22 
23 // "HTTP/1.1"
24 // RFC6455 only requires HTTP/1.1 "or better" but in practice an HTTP version
25 // other than 1.1 should not occur in a WebSocket handshake.
26 extern const char kHttpProtocolVersion[];
27 
28 // The Sec-WebSockey-Key challenge is 16 random bytes, base64 encoded.
29 inline constexpr size_t kRawChallengeLength = 16;
30 
31 // "Sec-WebSocket-Protocol"
32 extern const char kSecWebSocketProtocol[];
33 
34 // "Sec-WebSocket-Extensions"
35 extern const char kSecWebSocketExtensions[];
36 
37 // "Sec-WebSocket-Key"
38 extern const char kSecWebSocketKey[];
39 
40 // "Sec-WebSocket-Accept"
41 extern const char kSecWebSocketAccept[];
42 
43 // "Sec-WebSocket-Version"
44 extern const char kSecWebSocketVersion[];
45 
46 // This implementation only supports one version of the WebSocket protocol,
47 // "13", as specified in RFC6455. If support for multiple versions is added in
48 // future, it will probably no longer be worth having a constant for this.
49 extern const char kSupportedVersion[];
50 
51 // "Upgrade"
52 extern const char kUpgrade[];
53 
54 // "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" as defined in section 4.1 of
55 // RFC6455.
56 extern const char NET_EXPORT kWebSocketGuid[];
57 
58 // "websocket", as used in the "Upgrade:" header. This is always lowercase
59 // (except in obsolete versions of the protocol).
60 extern const char kWebSocketLowercase[];
61 
62 }  // namespace net::websockets
63 
64 #endif  // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_CONSTANTS_H_
65