blob: e1e184f56e21c6ace3dcce7e92c979f65cdecb6b [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_string_utils.h"
dmcardleba2fb7e2019-12-13 07:44:34 -080015#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 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,
QUICHE teama6ef0a62019-03-07 20:34:33 -050024 CANCEL_PUSH = 0X3,
25 SETTINGS = 0x4,
26 PUSH_PROMISE = 0x5,
27 GOAWAY = 0x7,
28 MAX_PUSH_ID = 0xD,
bnc51e89622020-01-10 10:40:32 -080029 DUPLICATE_PUSH = 0xE,
30 PRIORITY_UPDATE = 0XF,
QUICHE teama6ef0a62019-03-07 20:34:33 -050031};
32
bnc94b790c2020-01-10 10:14:46 -080033// 7.2.1. DATA
QUICHE teama6ef0a62019-03-07 20:34:33 -050034//
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 {
dmcardleba2fb7e2019-12-13 07:44:34 -080038 quiche::QuicheStringPiece data;
QUICHE teama6ef0a62019-03-07 20:34:33 -050039};
40
bnc94b790c2020-01-10 10:14:46 -080041// 7.2.2. HEADERS
QUICHE teama6ef0a62019-03-07 20:34:33 -050042//
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 {
dmcardleba2fb7e2019-12-13 07:44:34 -080046 quiche::QuicheStringPiece headers;
QUICHE teama6ef0a62019-03-07 20:34:33 -050047};
48
bnc94b790c2020-01-10 10:14:46 -080049// 7.2.3. CANCEL_PUSH
QUICHE teama6ef0a62019-03-07 20:34:33 -050050//
51// The CANCEL_PUSH frame (type=0x3) is used to request cancellation of
52// server push prior to the push stream being created.
53using PushId = uint64_t;
54
dschinazif25169a2019-10-23 08:12:18 -070055struct QUIC_EXPORT_PRIVATE CancelPushFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -050056 PushId push_id;
57
58 bool operator==(const CancelPushFrame& rhs) const {
59 return push_id == rhs.push_id;
60 }
61};
62
bnc94b790c2020-01-10 10:14:46 -080063// 7.2.4. SETTINGS
QUICHE teama6ef0a62019-03-07 20:34:33 -050064//
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
renjietang3b3e3b32019-04-22 18:01:20 -070069using SettingsMap = std::map<uint64_t, uint64_t>;
QUICHE teama6ef0a62019-03-07 20:34:33 -050070
dschinazif25169a2019-10-23 08:12:18 -070071struct QUIC_EXPORT_PRIVATE SettingsFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -050072 SettingsMap values;
73
74 bool operator==(const SettingsFrame& rhs) const {
75 return values == rhs.values;
76 }
renjietang790af402019-06-27 16:52:24 -070077
78 std::string ToString() const {
79 std::string s;
80 for (auto it : values) {
dmcardleba2fb7e2019-12-13 07:44:34 -080081 std::string setting = quiche::QuicheStrCat(
renjietang2db302b2019-09-23 12:40:17 -070082 SpdyUtils::H3SettingsToString(
83 static_cast<Http3AndQpackSettingsIdentifiers>(it.first)),
84 " = ", it.second, "; ");
renjietang790af402019-06-27 16:52:24 -070085 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 teama6ef0a62019-03-07 20:34:33 -050094};
95
bnc94b790c2020-01-10 10:14:46 -080096// 7.2.5. PUSH_PROMISE
QUICHE teama6ef0a62019-03-07 20:34:33 -050097//
98// The PUSH_PROMISE frame (type=0x05) is used to carry a request header
99// set from server to client, as in HTTP/2.
dschinazif25169a2019-10-23 08:12:18 -0700100struct QUIC_EXPORT_PRIVATE PushPromiseFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500101 PushId push_id;
dmcardleba2fb7e2019-12-13 07:44:34 -0800102 quiche::QuicheStringPiece headers;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500103
104 bool operator==(const PushPromiseFrame& rhs) const {
105 return push_id == rhs.push_id && headers == rhs.headers;
106 }
107};
108
bnc94b790c2020-01-10 10:14:46 -0800109// 7.2.6. GOAWAY
QUICHE teama6ef0a62019-03-07 20:34:33 -0500110//
111// The GOAWAY frame (type=0x7) is used to initiate graceful shutdown of
112// a connection by a server.
dschinazif25169a2019-10-23 08:12:18 -0700113struct QUIC_EXPORT_PRIVATE GoAwayFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500114 QuicStreamId stream_id;
115
116 bool operator==(const GoAwayFrame& rhs) const {
117 return stream_id == rhs.stream_id;
118 }
119};
120
bnc94b790c2020-01-10 10:14:46 -0800121// 7.2.7. MAX_PUSH_ID
QUICHE teama6ef0a62019-03-07 20:34:33 -0500122//
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.
dschinazif25169a2019-10-23 08:12:18 -0700125struct QUIC_EXPORT_PRIVATE MaxPushIdFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500126 PushId push_id;
127
128 bool operator==(const MaxPushIdFrame& rhs) const {
129 return push_id == rhs.push_id;
130 }
131};
132
bnc94b790c2020-01-10 10:14:46 -0800133// 7.2.8. DUPLICATE_PUSH
QUICHE teama6ef0a62019-03-07 20:34:33 -0500134//
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.
dschinazif25169a2019-10-23 08:12:18 -0700138struct QUIC_EXPORT_PRIVATE DuplicatePushFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500139 PushId push_id;
140
141 bool operator==(const DuplicatePushFrame& rhs) const {
142 return push_id == rhs.push_id;
143 }
144};
145
bnc51e89622020-01-10 10:40:32 -0800146// 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.
152const QuicByteCount kPriorityFirstByteLength = 1;
153
154enum PrioritizedElementType : uint8_t {
155 REQUEST_STREAM = 0x00,
156 PUSH_STREAM = 0x80,
157};
158
159struct 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 teama6ef0a62019-03-07 20:34:33 -0500186} // namespace quic
187
188#endif // QUICHE_QUIC_CORE_HTTP_HTTP_FRAMES_H_