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_string_utils.h" |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h" |
| 16 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.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, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 24 | CANCEL_PUSH = 0X3, |
| 25 | SETTINGS = 0x4, |
| 26 | PUSH_PROMISE = 0x5, |
| 27 | GOAWAY = 0x7, |
| 28 | MAX_PUSH_ID = 0xD, |
bnc | 51e8962 | 2020-01-10 10:40:32 -0800 | [diff] [blame] | 29 | DUPLICATE_PUSH = 0xE, |
| 30 | PRIORITY_UPDATE = 0XF, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 31 | }; |
| 32 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame] | 33 | // 7.2.1. DATA |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 { |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 38 | quiche::QuicheStringPiece data; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 39 | }; |
| 40 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame] | 41 | // 7.2.2. HEADERS |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 { |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 46 | quiche::QuicheStringPiece headers; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 47 | }; |
| 48 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame] | 49 | // 7.2.3. CANCEL_PUSH |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 50 | // |
| 51 | // The CANCEL_PUSH frame (type=0x3) is used to request cancellation of |
| 52 | // server push prior to the push stream being created. |
| 53 | using PushId = uint64_t; |
| 54 | |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 55 | struct QUIC_EXPORT_PRIVATE CancelPushFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 56 | PushId push_id; |
| 57 | |
| 58 | bool operator==(const CancelPushFrame& rhs) const { |
| 59 | return push_id == rhs.push_id; |
| 60 | } |
| 61 | }; |
| 62 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame] | 63 | // 7.2.4. SETTINGS |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 64 | // |
| 65 | // The SETTINGS frame (type=0x4) conveys configuration parameters that |
| 66 | // affect how endpoints communicate, such as preferences and constraints |
| 67 | // on peer behavior |
| 68 | |
renjietang | 3b3e3b3 | 2019-04-22 18:01:20 -0700 | [diff] [blame] | 69 | using SettingsMap = std::map<uint64_t, uint64_t>; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 70 | |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 71 | struct QUIC_EXPORT_PRIVATE SettingsFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 72 | SettingsMap values; |
| 73 | |
| 74 | bool operator==(const SettingsFrame& rhs) const { |
| 75 | return values == rhs.values; |
| 76 | } |
renjietang | 790af40 | 2019-06-27 16:52:24 -0700 | [diff] [blame] | 77 | |
| 78 | std::string ToString() const { |
| 79 | std::string s; |
| 80 | for (auto it : values) { |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 81 | std::string setting = quiche::QuicheStrCat( |
renjietang | 2db302b | 2019-09-23 12:40:17 -0700 | [diff] [blame] | 82 | SpdyUtils::H3SettingsToString( |
| 83 | static_cast<Http3AndQpackSettingsIdentifiers>(it.first)), |
| 84 | " = ", it.second, "; "); |
renjietang | 790af40 | 2019-06-27 16:52:24 -0700 | [diff] [blame] | 85 | QuicStrAppend(&s, setting); |
| 86 | } |
| 87 | return s; |
| 88 | } |
| 89 | friend QUIC_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, |
| 90 | const SettingsFrame& s) { |
| 91 | os << s.ToString(); |
| 92 | return os; |
| 93 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 94 | }; |
| 95 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame] | 96 | // 7.2.5. PUSH_PROMISE |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 97 | // |
| 98 | // The PUSH_PROMISE frame (type=0x05) is used to carry a request header |
| 99 | // set from server to client, as in HTTP/2. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 100 | struct QUIC_EXPORT_PRIVATE PushPromiseFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 101 | PushId push_id; |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 102 | quiche::QuicheStringPiece headers; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 103 | |
| 104 | bool operator==(const PushPromiseFrame& rhs) const { |
| 105 | return push_id == rhs.push_id && headers == rhs.headers; |
| 106 | } |
| 107 | }; |
| 108 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame] | 109 | // 7.2.6. GOAWAY |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 110 | // |
| 111 | // The GOAWAY frame (type=0x7) is used to initiate graceful shutdown of |
| 112 | // a connection by a server. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 113 | struct QUIC_EXPORT_PRIVATE GoAwayFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 114 | QuicStreamId stream_id; |
| 115 | |
| 116 | bool operator==(const GoAwayFrame& rhs) const { |
| 117 | return stream_id == rhs.stream_id; |
| 118 | } |
| 119 | }; |
| 120 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame] | 121 | // 7.2.7. MAX_PUSH_ID |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 122 | // |
| 123 | // The MAX_PUSH_ID frame (type=0xD) is used by clients to control the |
| 124 | // number of server pushes that the server can initiate. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 125 | struct QUIC_EXPORT_PRIVATE MaxPushIdFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 126 | PushId push_id; |
| 127 | |
| 128 | bool operator==(const MaxPushIdFrame& rhs) const { |
| 129 | return push_id == rhs.push_id; |
| 130 | } |
| 131 | }; |
| 132 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame] | 133 | // 7.2.8. DUPLICATE_PUSH |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 134 | // |
| 135 | // The DUPLICATE_PUSH frame (type=0xE) is used by servers to indicate |
| 136 | // that an existing pushed resource is related to multiple client |
| 137 | // requests. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 138 | struct QUIC_EXPORT_PRIVATE DuplicatePushFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 139 | PushId push_id; |
| 140 | |
| 141 | bool operator==(const DuplicatePushFrame& rhs) const { |
| 142 | return push_id == rhs.push_id; |
| 143 | } |
| 144 | }; |
| 145 | |
bnc | 51e8962 | 2020-01-10 10:40:32 -0800 | [diff] [blame] | 146 | // https://httpwg.org/http-extensions/draft-ietf-httpbis-priority.html |
| 147 | // |
| 148 | // The PRIORITY_UPDATE (type=0x0f) frame specifies the sender-advised priority |
| 149 | // of a stream |
| 150 | |
| 151 | // Length of a priority frame's first byte. |
| 152 | const QuicByteCount kPriorityFirstByteLength = 1; |
| 153 | |
| 154 | enum PrioritizedElementType : uint8_t { |
| 155 | REQUEST_STREAM = 0x00, |
| 156 | PUSH_STREAM = 0x80, |
| 157 | }; |
| 158 | |
| 159 | struct QUIC_EXPORT_PRIVATE PriorityUpdateFrame { |
| 160 | PrioritizedElementType prioritized_element_type = REQUEST_STREAM; |
| 161 | uint64_t prioritized_element_id = 0; |
| 162 | std::string priority_field_value; |
| 163 | |
| 164 | bool operator==(const PriorityUpdateFrame& rhs) const { |
| 165 | return std::tie(prioritized_element_type, prioritized_element_id, |
| 166 | priority_field_value) == |
| 167 | std::tie(rhs.prioritized_element_type, rhs.prioritized_element_id, |
| 168 | rhs.priority_field_value); |
| 169 | } |
| 170 | std::string ToString() const { |
| 171 | return quiche::QuicheStrCat( |
| 172 | "Priority Frame : {prioritized_element_type: ", |
| 173 | static_cast<int>(prioritized_element_type), |
| 174 | ", prioritized_element_id: ", prioritized_element_id, |
| 175 | ", priority_field_value: ", priority_field_value, "}"); |
| 176 | } |
| 177 | |
| 178 | friend QUIC_EXPORT_PRIVATE std::ostream& operator<<( |
| 179 | std::ostream& os, |
| 180 | const PriorityUpdateFrame& s) { |
| 181 | os << s.ToString(); |
| 182 | return os; |
| 183 | } |
| 184 | }; |
| 185 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 186 | } // namespace quic |
| 187 | |
| 188 | #endif // QUICHE_QUIC_CORE_HTTP_HTTP_FRAMES_H_ |