1 | // Licensed to the Apache Software Foundation (ASF) under one |
2 | // or more contributor license agreements. See the NOTICE file |
3 | // distributed with this work for additional information |
4 | // regarding copyright ownership. The ASF licenses this file |
5 | // to you under the Apache License, Version 2.0 (the |
6 | // "License"); you may not use this file except in compliance |
7 | // with the License. You may obtain a copy of the License at |
8 | // |
9 | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | // |
11 | // Unless required by applicable law or agreed to in writing, |
12 | // software distributed under the License is distributed on an |
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | // KIND, either express or implied. See the License for the |
15 | // specific language governing permissions and limitations |
16 | // under the License. |
17 | |
18 | #ifndef BAIDU_RPC_HTTP2_H |
19 | #define BAIDU_RPC_HTTP2_H |
20 | |
21 | #include "brpc/http_status_code.h" |
22 | |
23 | // To baidu-rpc developers: This is a header included by user, don't depend |
24 | // on internal structures, use opaque pointers instead. |
25 | |
26 | namespace brpc { |
27 | |
28 | struct H2Settings { |
29 | // Construct with default values. |
30 | H2Settings(); |
31 | |
32 | // Returns true iff all options are valid. |
33 | bool IsValid(bool log_error = false) const; |
34 | |
35 | // Allows the sender to inform the remote endpoint of the maximum size of |
36 | // the header compression table used to decode header blocks, in octets. |
37 | // The encoder can select any size equal to or less than this value by |
38 | // using signaling specific to the header compression format inside a |
39 | // header block (see [COMPRESSION]). |
40 | // Default: 4096 |
41 | static const uint32_t = 4096; |
42 | uint32_t ; |
43 | |
44 | // Enable server push or not (Section 8.2). |
45 | // An endpoint MUST NOT send a PUSH_PROMISE frame if it receives this |
46 | // parameter set to a value of 0. An endpoint that has both set this |
47 | // parameter to 0 and had it acknowledged MUST treat the receipt of a |
48 | // PUSH_PROMISE frame as a connection error (Section 5.4.1) of type |
49 | // PROTOCOL_ERROR. |
50 | // Default: false (server push is disabled) |
51 | static const bool DEFAULT_ENABLE_PUSH = true; |
52 | bool enable_push; |
53 | |
54 | // The maximum number of concurrent streams that the sender will allow. |
55 | // This limit is directional: it applies to the number of streams that the |
56 | // sender permits the receiver to create. It is recommended that this value |
57 | // be no smaller than 100, so as to not unnecessarily limit parallelism. |
58 | // 0 prevents the creation of new streams. However, this can also happen |
59 | // for any limit that is exhausted with active streams. Servers SHOULD only |
60 | // set a zero value for short durations; if a server does not wish to |
61 | // accept requests, closing the connection is more appropriate. |
62 | // Default: unlimited |
63 | uint32_t max_concurrent_streams; |
64 | |
65 | // Sender's initial window size (in octets) for stream-level flow control. |
66 | // This setting affects the window size of all streams (see Section 6.9.2). |
67 | // Values above the maximum flow-control window size of 2^31-1 are treated |
68 | // as a connection error (Section 5.4.1) of type FLOW_CONTROL_ERROR |
69 | // Default: 256 * 1024 |
70 | static const uint32_t DEFAULT_INITIAL_WINDOW_SIZE = 65535; |
71 | static const uint32_t MAX_WINDOW_SIZE = (1u << 31) - 1; |
72 | uint32_t stream_window_size; |
73 | |
74 | // Initial window size for connection-level flow control. |
75 | // Default: 1024 * 1024 |
76 | // Setting to zero stops printing this field. |
77 | uint32_t connection_window_size; |
78 | |
79 | // Size of the largest frame payload that the sender is willing to receive, |
80 | // in octets. The value advertised by an endpoint MUST be between 16384 and |
81 | // 16777215, inclusive. Values outside this range are treated as a |
82 | // connection error(Section 5.4.1) of type PROTOCOL_ERROR. |
83 | // Default: 16384 |
84 | static const uint32_t DEFAULT_MAX_FRAME_SIZE = 16384; |
85 | static const uint32_t MAX_OF_MAX_FRAME_SIZE = 16777215; |
86 | uint32_t max_frame_size; |
87 | |
88 | // This advisory setting informs a peer of the maximum size of header list |
89 | // that the sender is prepared to accept, in octets. The value is based on |
90 | // the uncompressed size of header fields, including the length of the name |
91 | // and value in octets plus an overhead of 32 octets for each header field. |
92 | // For any given request, a lower limit than what is advertised MAY be |
93 | // enforced. |
94 | // Default: unlimited. |
95 | uint32_t ; |
96 | }; |
97 | |
98 | std::ostream& operator<<(std::ostream& os, const H2Settings& s); |
99 | |
100 | enum H2Error { |
101 | H2_NO_ERROR = 0x0, // Graceful shutdown |
102 | H2_PROTOCOL_ERROR = 0x1, // Protocol error detected |
103 | H2_INTERNAL_ERROR = 0x2, // Implementation fault |
104 | H2_FLOW_CONTROL_ERROR = 0x3, // Flow-control limits exceeded |
105 | H2_SETTINGS_TIMEOUT = 0x4, // Settings not acknowledged |
106 | H2_STREAM_CLOSED_ERROR = 0x5, // Frame received for closed stream |
107 | H2_FRAME_SIZE_ERROR = 0x6, // Frame size incorrect |
108 | H2_REFUSED_STREAM = 0x7, // Stream not processed |
109 | H2_CANCEL = 0x8, // Stream cancelled |
110 | H2_COMPRESSION_ERROR = 0x9, // Compression state not updated |
111 | H2_CONNECT_ERROR = 0xa, // TCP connection error for CONNECT method |
112 | H2_ENHANCE_YOUR_CALM = 0xb, // Processing capacity exceeded |
113 | H2_INADEQUATE_SECURITY = 0xc, // Negotiated TLS parameters not acceptable |
114 | H2_HTTP_1_1_REQUIRED = 0xd, // Use HTTP/1.1 for the request |
115 | }; |
116 | |
117 | // Get description of the error. |
118 | const char* H2ErrorToString(H2Error e); |
119 | |
120 | // Convert the error to status code with similar semantics |
121 | int H2ErrorToStatusCode(H2Error e); |
122 | |
123 | } // namespace brpc |
124 | |
125 | #endif // BAIDU_RPC_HTTP2_H |
126 | |