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, |
| 29 | DUPLICATE_PUSH = 0xE |
| 30 | }; |
| 31 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame^] | 32 | // 7.2.1. DATA |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 33 | // |
| 34 | // DATA frames (type=0x0) convey arbitrary, variable-length sequences of |
| 35 | // octets associated with an HTTP request or response payload. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 36 | struct QUIC_EXPORT_PRIVATE DataFrame { |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 37 | quiche::QuicheStringPiece data; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 38 | }; |
| 39 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame^] | 40 | // 7.2.2. HEADERS |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 41 | // |
| 42 | // The HEADERS frame (type=0x1) is used to carry a header block, |
| 43 | // compressed using QPACK. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 44 | struct QUIC_EXPORT_PRIVATE HeadersFrame { |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 45 | quiche::QuicheStringPiece headers; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 46 | }; |
| 47 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame^] | 48 | // 7.2.3. CANCEL_PUSH |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 49 | // |
| 50 | // The CANCEL_PUSH frame (type=0x3) is used to request cancellation of |
| 51 | // server push prior to the push stream being created. |
| 52 | using PushId = uint64_t; |
| 53 | |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 54 | struct QUIC_EXPORT_PRIVATE CancelPushFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 55 | PushId push_id; |
| 56 | |
| 57 | bool operator==(const CancelPushFrame& rhs) const { |
| 58 | return push_id == rhs.push_id; |
| 59 | } |
| 60 | }; |
| 61 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame^] | 62 | // 7.2.4. SETTINGS |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 63 | // |
| 64 | // The SETTINGS frame (type=0x4) conveys configuration parameters that |
| 65 | // affect how endpoints communicate, such as preferences and constraints |
| 66 | // on peer behavior |
| 67 | |
renjietang | 3b3e3b3 | 2019-04-22 18:01:20 -0700 | [diff] [blame] | 68 | using SettingsMap = std::map<uint64_t, uint64_t>; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 69 | |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 70 | struct QUIC_EXPORT_PRIVATE SettingsFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 71 | SettingsMap values; |
| 72 | |
| 73 | bool operator==(const SettingsFrame& rhs) const { |
| 74 | return values == rhs.values; |
| 75 | } |
renjietang | 790af40 | 2019-06-27 16:52:24 -0700 | [diff] [blame] | 76 | |
| 77 | std::string ToString() const { |
| 78 | std::string s; |
| 79 | for (auto it : values) { |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 80 | std::string setting = quiche::QuicheStrCat( |
renjietang | 2db302b | 2019-09-23 12:40:17 -0700 | [diff] [blame] | 81 | SpdyUtils::H3SettingsToString( |
| 82 | static_cast<Http3AndQpackSettingsIdentifiers>(it.first)), |
| 83 | " = ", it.second, "; "); |
renjietang | 790af40 | 2019-06-27 16:52:24 -0700 | [diff] [blame] | 84 | QuicStrAppend(&s, setting); |
| 85 | } |
| 86 | return s; |
| 87 | } |
| 88 | friend QUIC_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, |
| 89 | const SettingsFrame& s) { |
| 90 | os << s.ToString(); |
| 91 | return os; |
| 92 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 93 | }; |
| 94 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame^] | 95 | // 7.2.5. PUSH_PROMISE |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 96 | // |
| 97 | // The PUSH_PROMISE frame (type=0x05) is used to carry a request header |
| 98 | // set from server to client, as in HTTP/2. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 99 | struct QUIC_EXPORT_PRIVATE PushPromiseFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 100 | PushId push_id; |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 101 | quiche::QuicheStringPiece headers; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 102 | |
| 103 | bool operator==(const PushPromiseFrame& rhs) const { |
| 104 | return push_id == rhs.push_id && headers == rhs.headers; |
| 105 | } |
| 106 | }; |
| 107 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame^] | 108 | // 7.2.6. GOAWAY |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 109 | // |
| 110 | // The GOAWAY frame (type=0x7) is used to initiate graceful shutdown of |
| 111 | // a connection by a server. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 112 | struct QUIC_EXPORT_PRIVATE GoAwayFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 113 | QuicStreamId stream_id; |
| 114 | |
| 115 | bool operator==(const GoAwayFrame& rhs) const { |
| 116 | return stream_id == rhs.stream_id; |
| 117 | } |
| 118 | }; |
| 119 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame^] | 120 | // 7.2.7. MAX_PUSH_ID |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 121 | // |
| 122 | // The MAX_PUSH_ID frame (type=0xD) is used by clients to control the |
| 123 | // number of server pushes that the server can initiate. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 124 | struct QUIC_EXPORT_PRIVATE MaxPushIdFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 125 | PushId push_id; |
| 126 | |
| 127 | bool operator==(const MaxPushIdFrame& rhs) const { |
| 128 | return push_id == rhs.push_id; |
| 129 | } |
| 130 | }; |
| 131 | |
bnc | 94b790c | 2020-01-10 10:14:46 -0800 | [diff] [blame^] | 132 | // 7.2.8. DUPLICATE_PUSH |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 133 | // |
| 134 | // The DUPLICATE_PUSH frame (type=0xE) is used by servers to indicate |
| 135 | // that an existing pushed resource is related to multiple client |
| 136 | // requests. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 137 | struct QUIC_EXPORT_PRIVATE DuplicatePushFrame { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 138 | PushId push_id; |
| 139 | |
| 140 | bool operator==(const DuplicatePushFrame& rhs) const { |
| 141 | return push_id == rhs.push_id; |
| 142 | } |
| 143 | }; |
| 144 | |
| 145 | } // namespace quic |
| 146 | |
| 147 | #endif // QUICHE_QUIC_CORE_HTTP_HTTP_FRAMES_H_ |