QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef QUICHE_QUIC_CORE_HTTP_HTTP_FRAMES_H_ |
| 6 | #define QUICHE_QUIC_CORE_HTTP_HTTP_FRAMES_H_ |
| 7 | |
renjietang | 3a76c89 | 2019-07-17 10:03:53 -0700 | [diff] [blame] | 8 | #include <cstdint> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | #include <map> |
renjietang | 790af40 | 2019-06-27 16:52:24 -0700 | [diff] [blame] | 10 | #include <ostream> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11 | |
renjietang | 2db302b | 2019-09-23 12:40:17 -0700 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/quic/core/http/spdy_utils.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
renjietang | 790af40 | 2019-06-27 16:52:24 -0700 | [diff] [blame] | 14 | #include "net/third_party/quiche/src/quic/platform/api/quic_str_cat.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h" |
renjietang | 790af40 | 2019-06-27 16:52:24 -0700 | [diff] [blame] | 16 | #include "net/third_party/quiche/src/quic/platform/api/quic_string_utils.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
| 18 | |
| 19 | namespace quic { |
| 20 | |
| 21 | enum class HttpFrameType : uint8_t { |
| 22 | DATA = 0x0, |
| 23 | HEADERS = 0x1, |
| 24 | PRIORITY = 0X2, |
| 25 | CANCEL_PUSH = 0X3, |
| 26 | SETTINGS = 0x4, |
| 27 | PUSH_PROMISE = 0x5, |
| 28 | GOAWAY = 0x7, |
| 29 | MAX_PUSH_ID = 0xD, |
| 30 | DUPLICATE_PUSH = 0xE |
| 31 | }; |
| 32 | |
| 33 | // 4.2.1. DATA |
| 34 | // |
| 35 | // DATA frames (type=0x0) convey arbitrary, variable-length sequences of |
| 36 | // octets associated with an HTTP request or response payload. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 37 | struct QUIC_EXPORT_PRIVATE DataFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 38 | QuicStringPiece data; |
| 39 | }; |
| 40 | |
| 41 | // 4.2.2. HEADERS |
| 42 | // |
| 43 | // The HEADERS frame (type=0x1) is used to carry a header block, |
| 44 | // compressed using QPACK. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 45 | struct QUIC_EXPORT_PRIVATE HeadersFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 46 | QuicStringPiece headers; |
| 47 | }; |
| 48 | |
| 49 | // 4.2.3. PRIORITY |
| 50 | // |
| 51 | // The PRIORITY (type=0x02) frame specifies the sender-advised priority |
| 52 | // of a stream |
bnc | efbda66 | 2019-07-17 17:01:13 -0700 | [diff] [blame] | 53 | |
| 54 | // Length of the weight field of a priority frame. |
| 55 | const QuicByteCount kPriorityWeightLength = 1; |
| 56 | // Length of a priority frame's first byte. |
| 57 | const QuicByteCount kPriorityFirstByteLength = 1; |
| 58 | // The bit that indicates Priority frame is exclusive. |
| 59 | const uint8_t kPriorityExclusiveBit = 8; |
| 60 | |
renjietang | 3a76c89 | 2019-07-17 10:03:53 -0700 | [diff] [blame] | 61 | enum PriorityElementType : uint8_t { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 62 | REQUEST_STREAM = 0, |
| 63 | PUSH_STREAM = 1, |
| 64 | PLACEHOLDER = 2, |
| 65 | ROOT_OF_TREE = 3 |
| 66 | }; |
| 67 | |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 68 | struct QUIC_EXPORT_PRIVATE PriorityFrame { |
renjietang | ec09576 | 2019-06-19 14:35:02 -0700 | [diff] [blame] | 69 | PriorityElementType prioritized_type = REQUEST_STREAM; |
| 70 | PriorityElementType dependency_type = REQUEST_STREAM; |
| 71 | bool exclusive = false; |
| 72 | uint64_t prioritized_element_id = 0; |
| 73 | uint64_t element_dependency_id = 0; |
| 74 | uint8_t weight = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 75 | |
| 76 | bool operator==(const PriorityFrame& rhs) const { |
| 77 | return prioritized_type == rhs.prioritized_type && |
| 78 | dependency_type == rhs.dependency_type && |
| 79 | exclusive == rhs.exclusive && |
| 80 | prioritized_element_id == rhs.prioritized_element_id && |
| 81 | element_dependency_id == rhs.element_dependency_id && |
| 82 | weight == rhs.weight; |
| 83 | } |
renjietang | 4a6b905 | 2019-07-22 15:49:50 -0700 | [diff] [blame] | 84 | std::string ToString() const { |
| 85 | return QuicStrCat("Priority Frame : {prioritized_type: ", prioritized_type, |
| 86 | ", dependency_type: ", dependency_type, |
| 87 | ", exclusive: ", exclusive, |
| 88 | ", prioritized_element_id: ", prioritized_element_id, |
| 89 | ", element_dependency_id: ", element_dependency_id, |
| 90 | ", weight: ", weight, "}"); |
| 91 | } |
| 92 | |
| 93 | friend QUIC_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, |
| 94 | const PriorityFrame& s) { |
| 95 | os << s.ToString(); |
| 96 | return os; |
| 97 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | // 4.2.4. CANCEL_PUSH |
| 101 | // |
| 102 | // The CANCEL_PUSH frame (type=0x3) is used to request cancellation of |
| 103 | // server push prior to the push stream being created. |
| 104 | using PushId = uint64_t; |
| 105 | |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 106 | struct QUIC_EXPORT_PRIVATE CancelPushFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 107 | PushId push_id; |
| 108 | |
| 109 | bool operator==(const CancelPushFrame& rhs) const { |
| 110 | return push_id == rhs.push_id; |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | // 4.2.5. SETTINGS |
| 115 | // |
| 116 | // The SETTINGS frame (type=0x4) conveys configuration parameters that |
| 117 | // affect how endpoints communicate, such as preferences and constraints |
| 118 | // on peer behavior |
| 119 | |
renjietang | 3b3e3b3 | 2019-04-22 18:01:20 -0700 | [diff] [blame] | 120 | using SettingsMap = std::map<uint64_t, uint64_t>; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 121 | |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 122 | struct QUIC_EXPORT_PRIVATE SettingsFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 123 | SettingsMap values; |
| 124 | |
| 125 | bool operator==(const SettingsFrame& rhs) const { |
| 126 | return values == rhs.values; |
| 127 | } |
renjietang | 790af40 | 2019-06-27 16:52:24 -0700 | [diff] [blame] | 128 | |
| 129 | std::string ToString() const { |
| 130 | std::string s; |
| 131 | for (auto it : values) { |
renjietang | 2db302b | 2019-09-23 12:40:17 -0700 | [diff] [blame] | 132 | std::string setting = QuicStrCat( |
| 133 | SpdyUtils::H3SettingsToString( |
| 134 | static_cast<Http3AndQpackSettingsIdentifiers>(it.first)), |
| 135 | " = ", it.second, "; "); |
renjietang | 790af40 | 2019-06-27 16:52:24 -0700 | [diff] [blame] | 136 | QuicStrAppend(&s, setting); |
| 137 | } |
| 138 | return s; |
| 139 | } |
| 140 | friend QUIC_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, |
| 141 | const SettingsFrame& s) { |
| 142 | os << s.ToString(); |
| 143 | return os; |
| 144 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | // 4.2.6. PUSH_PROMISE |
| 148 | // |
| 149 | // The PUSH_PROMISE frame (type=0x05) is used to carry a request header |
| 150 | // set from server to client, as in HTTP/2. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 151 | struct QUIC_EXPORT_PRIVATE PushPromiseFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 152 | PushId push_id; |
| 153 | QuicStringPiece headers; |
| 154 | |
| 155 | bool operator==(const PushPromiseFrame& rhs) const { |
| 156 | return push_id == rhs.push_id && headers == rhs.headers; |
| 157 | } |
| 158 | }; |
| 159 | |
| 160 | // 4.2.7. GOAWAY |
| 161 | // |
| 162 | // The GOAWAY frame (type=0x7) is used to initiate graceful shutdown of |
| 163 | // a connection by a server. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 164 | struct QUIC_EXPORT_PRIVATE GoAwayFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 165 | QuicStreamId stream_id; |
| 166 | |
| 167 | bool operator==(const GoAwayFrame& rhs) const { |
| 168 | return stream_id == rhs.stream_id; |
| 169 | } |
| 170 | }; |
| 171 | |
| 172 | // 4.2.8. MAX_PUSH_ID |
| 173 | // |
| 174 | // The MAX_PUSH_ID frame (type=0xD) is used by clients to control the |
| 175 | // number of server pushes that the server can initiate. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 176 | struct QUIC_EXPORT_PRIVATE MaxPushIdFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 177 | PushId push_id; |
| 178 | |
| 179 | bool operator==(const MaxPushIdFrame& rhs) const { |
| 180 | return push_id == rhs.push_id; |
| 181 | } |
| 182 | }; |
| 183 | |
| 184 | // 4.2.9. DUPLICATE_PUSH |
| 185 | // |
| 186 | // The DUPLICATE_PUSH frame (type=0xE) is used by servers to indicate |
| 187 | // that an existing pushed resource is related to multiple client |
| 188 | // requests. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 189 | struct QUIC_EXPORT_PRIVATE DuplicatePushFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 190 | PushId push_id; |
| 191 | |
| 192 | bool operator==(const DuplicatePushFrame& rhs) const { |
| 193 | return push_id == rhs.push_id; |
| 194 | } |
| 195 | }; |
| 196 | |
| 197 | } // namespace quic |
| 198 | |
| 199 | #endif // QUICHE_QUIC_CORE_HTTP_HTTP_FRAMES_H_ |