blob: 215fa568d29a9fb3ee7c783fa00b8f6a3ce21cd2 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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
renjietang3a76c892019-07-17 10:03:53 -07008#include <cstdint>
QUICHE teama6ef0a62019-03-07 20:34:33 -05009#include <map>
renjietang790af402019-06-27 16:52:24 -070010#include <ostream>
QUICHE teama6ef0a62019-03-07 20:34:33 -050011
renjietang2db302b2019-09-23 12:40:17 -070012#include "net/third_party/quiche/src/quic/core/http/spdy_utils.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050013#include "net/third_party/quiche/src/quic/core/quic_types.h"
renjietang790af402019-06-27 16:52:24 -070014#include "net/third_party/quiche/src/quic/platform/api/quic_str_cat.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050015#include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h"
renjietang790af402019-06-27 16:52:24 -070016#include "net/third_party/quiche/src/quic/platform/api/quic_string_utils.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050017#include "net/third_party/quiche/src/spdy/core/spdy_framer.h"
18
19namespace quic {
20
21enum 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.
dschinazif25169a2019-10-23 08:12:18 -070037struct QUIC_EXPORT_PRIVATE DataFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -050038 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.
dschinazif25169a2019-10-23 08:12:18 -070045struct QUIC_EXPORT_PRIVATE HeadersFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -050046 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
bncefbda662019-07-17 17:01:13 -070053
54// Length of the weight field of a priority frame.
55const QuicByteCount kPriorityWeightLength = 1;
56// Length of a priority frame's first byte.
57const QuicByteCount kPriorityFirstByteLength = 1;
58// The bit that indicates Priority frame is exclusive.
59const uint8_t kPriorityExclusiveBit = 8;
60
renjietang3a76c892019-07-17 10:03:53 -070061enum PriorityElementType : uint8_t {
QUICHE teama6ef0a62019-03-07 20:34:33 -050062 REQUEST_STREAM = 0,
63 PUSH_STREAM = 1,
64 PLACEHOLDER = 2,
65 ROOT_OF_TREE = 3
66};
67
dschinazif25169a2019-10-23 08:12:18 -070068struct QUIC_EXPORT_PRIVATE PriorityFrame {
renjietangec095762019-06-19 14:35:02 -070069 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 teama6ef0a62019-03-07 20:34:33 -050075
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 }
renjietang4a6b9052019-07-22 15:49:50 -070084 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 teama6ef0a62019-03-07 20:34:33 -050098};
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.
104using PushId = uint64_t;
105
dschinazif25169a2019-10-23 08:12:18 -0700106struct QUIC_EXPORT_PRIVATE CancelPushFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500107 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
renjietang3b3e3b32019-04-22 18:01:20 -0700120using SettingsMap = std::map<uint64_t, uint64_t>;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500121
dschinazif25169a2019-10-23 08:12:18 -0700122struct QUIC_EXPORT_PRIVATE SettingsFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500123 SettingsMap values;
124
125 bool operator==(const SettingsFrame& rhs) const {
126 return values == rhs.values;
127 }
renjietang790af402019-06-27 16:52:24 -0700128
129 std::string ToString() const {
130 std::string s;
131 for (auto it : values) {
renjietang2db302b2019-09-23 12:40:17 -0700132 std::string setting = QuicStrCat(
133 SpdyUtils::H3SettingsToString(
134 static_cast<Http3AndQpackSettingsIdentifiers>(it.first)),
135 " = ", it.second, "; ");
renjietang790af402019-06-27 16:52:24 -0700136 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 teama6ef0a62019-03-07 20:34:33 -0500145};
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.
dschinazif25169a2019-10-23 08:12:18 -0700151struct QUIC_EXPORT_PRIVATE PushPromiseFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500152 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.
dschinazif25169a2019-10-23 08:12:18 -0700164struct QUIC_EXPORT_PRIVATE GoAwayFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500165 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.
dschinazif25169a2019-10-23 08:12:18 -0700176struct QUIC_EXPORT_PRIVATE MaxPushIdFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500177 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.
dschinazif25169a2019-10-23 08:12:18 -0700189struct QUIC_EXPORT_PRIVATE DuplicatePushFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500190 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_