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 | |
| 8 | #include <map> |
| 9 | |
| 10 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
| 11 | #include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h" |
| 12 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
| 13 | |
| 14 | namespace quic { |
| 15 | |
| 16 | enum class HttpFrameType : uint8_t { |
| 17 | DATA = 0x0, |
| 18 | HEADERS = 0x1, |
| 19 | PRIORITY = 0X2, |
| 20 | CANCEL_PUSH = 0X3, |
| 21 | SETTINGS = 0x4, |
| 22 | PUSH_PROMISE = 0x5, |
| 23 | GOAWAY = 0x7, |
| 24 | MAX_PUSH_ID = 0xD, |
| 25 | DUPLICATE_PUSH = 0xE |
| 26 | }; |
| 27 | |
| 28 | // 4.2.1. DATA |
| 29 | // |
| 30 | // DATA frames (type=0x0) convey arbitrary, variable-length sequences of |
| 31 | // octets associated with an HTTP request or response payload. |
| 32 | struct DataFrame { |
| 33 | QuicStringPiece data; |
| 34 | }; |
| 35 | |
| 36 | // 4.2.2. HEADERS |
| 37 | // |
| 38 | // The HEADERS frame (type=0x1) is used to carry a header block, |
| 39 | // compressed using QPACK. |
| 40 | struct HeadersFrame { |
| 41 | QuicStringPiece headers; |
| 42 | }; |
| 43 | |
| 44 | // 4.2.3. PRIORITY |
| 45 | // |
| 46 | // The PRIORITY (type=0x02) frame specifies the sender-advised priority |
| 47 | // of a stream |
| 48 | enum PriorityElementType { |
| 49 | REQUEST_STREAM = 0, |
| 50 | PUSH_STREAM = 1, |
| 51 | PLACEHOLDER = 2, |
| 52 | ROOT_OF_TREE = 3 |
| 53 | }; |
| 54 | |
| 55 | struct PriorityFrame { |
| 56 | PriorityElementType prioritized_type; |
| 57 | PriorityElementType dependency_type; |
| 58 | bool exclusive; |
| 59 | uint64_t prioritized_element_id; |
| 60 | uint64_t element_dependency_id; |
| 61 | uint8_t weight; |
| 62 | |
| 63 | bool operator==(const PriorityFrame& rhs) const { |
| 64 | return prioritized_type == rhs.prioritized_type && |
| 65 | dependency_type == rhs.dependency_type && |
| 66 | exclusive == rhs.exclusive && |
| 67 | prioritized_element_id == rhs.prioritized_element_id && |
| 68 | element_dependency_id == rhs.element_dependency_id && |
| 69 | weight == rhs.weight; |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | // 4.2.4. CANCEL_PUSH |
| 74 | // |
| 75 | // The CANCEL_PUSH frame (type=0x3) is used to request cancellation of |
| 76 | // server push prior to the push stream being created. |
| 77 | using PushId = uint64_t; |
| 78 | |
| 79 | struct CancelPushFrame { |
| 80 | PushId push_id; |
| 81 | |
| 82 | bool operator==(const CancelPushFrame& rhs) const { |
| 83 | return push_id == rhs.push_id; |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | // 4.2.5. SETTINGS |
| 88 | // |
| 89 | // The SETTINGS frame (type=0x4) conveys configuration parameters that |
| 90 | // affect how endpoints communicate, such as preferences and constraints |
| 91 | // on peer behavior |
| 92 | |
renjietang | 3b3e3b3 | 2019-04-22 18:01:20 -0700 | [diff] [blame] | 93 | using SettingsMap = std::map<uint64_t, uint64_t>; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 94 | |
| 95 | struct SettingsFrame { |
| 96 | SettingsMap values; |
| 97 | |
| 98 | bool operator==(const SettingsFrame& rhs) const { |
| 99 | return values == rhs.values; |
| 100 | } |
| 101 | }; |
| 102 | |
| 103 | // 4.2.6. PUSH_PROMISE |
| 104 | // |
| 105 | // The PUSH_PROMISE frame (type=0x05) is used to carry a request header |
| 106 | // set from server to client, as in HTTP/2. |
| 107 | struct PushPromiseFrame { |
| 108 | PushId push_id; |
| 109 | QuicStringPiece headers; |
| 110 | |
| 111 | bool operator==(const PushPromiseFrame& rhs) const { |
| 112 | return push_id == rhs.push_id && headers == rhs.headers; |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | // 4.2.7. GOAWAY |
| 117 | // |
| 118 | // The GOAWAY frame (type=0x7) is used to initiate graceful shutdown of |
| 119 | // a connection by a server. |
| 120 | struct GoAwayFrame { |
| 121 | QuicStreamId stream_id; |
| 122 | |
| 123 | bool operator==(const GoAwayFrame& rhs) const { |
| 124 | return stream_id == rhs.stream_id; |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | // 4.2.8. MAX_PUSH_ID |
| 129 | // |
| 130 | // The MAX_PUSH_ID frame (type=0xD) is used by clients to control the |
| 131 | // number of server pushes that the server can initiate. |
| 132 | struct MaxPushIdFrame { |
| 133 | PushId push_id; |
| 134 | |
| 135 | bool operator==(const MaxPushIdFrame& rhs) const { |
| 136 | return push_id == rhs.push_id; |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | // 4.2.9. DUPLICATE_PUSH |
| 141 | // |
| 142 | // The DUPLICATE_PUSH frame (type=0xE) is used by servers to indicate |
| 143 | // that an existing pushed resource is related to multiple client |
| 144 | // requests. |
| 145 | struct DuplicatePushFrame { |
| 146 | PushId push_id; |
| 147 | |
| 148 | bool operator==(const DuplicatePushFrame& rhs) const { |
| 149 | return push_id == rhs.push_id; |
| 150 | } |
| 151 | }; |
| 152 | |
| 153 | } // namespace quic |
| 154 | |
| 155 | #endif // QUICHE_QUIC_CORE_HTTP_HTTP_FRAMES_H_ |