blob: 6ad6da7872d69c0210b4d5a8bfa01f7a7a070692 [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,
29 DUPLICATE_PUSH = 0xE
30};
31
bnc94b790c2020-01-10 10:14:46 -080032// 7.2.1. DATA
QUICHE teama6ef0a62019-03-07 20:34:33 -050033//
34// DATA frames (type=0x0) convey arbitrary, variable-length sequences of
35// octets associated with an HTTP request or response payload.
dschinazif25169a2019-10-23 08:12:18 -070036struct QUIC_EXPORT_PRIVATE DataFrame {
dmcardleba2fb7e2019-12-13 07:44:34 -080037 quiche::QuicheStringPiece data;
QUICHE teama6ef0a62019-03-07 20:34:33 -050038};
39
bnc94b790c2020-01-10 10:14:46 -080040// 7.2.2. HEADERS
QUICHE teama6ef0a62019-03-07 20:34:33 -050041//
42// The HEADERS frame (type=0x1) is used to carry a header block,
43// compressed using QPACK.
dschinazif25169a2019-10-23 08:12:18 -070044struct QUIC_EXPORT_PRIVATE HeadersFrame {
dmcardleba2fb7e2019-12-13 07:44:34 -080045 quiche::QuicheStringPiece headers;
QUICHE teama6ef0a62019-03-07 20:34:33 -050046};
47
bnc94b790c2020-01-10 10:14:46 -080048// 7.2.3. CANCEL_PUSH
QUICHE teama6ef0a62019-03-07 20:34:33 -050049//
50// The CANCEL_PUSH frame (type=0x3) is used to request cancellation of
51// server push prior to the push stream being created.
52using PushId = uint64_t;
53
dschinazif25169a2019-10-23 08:12:18 -070054struct QUIC_EXPORT_PRIVATE CancelPushFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -050055 PushId push_id;
56
57 bool operator==(const CancelPushFrame& rhs) const {
58 return push_id == rhs.push_id;
59 }
60};
61
bnc94b790c2020-01-10 10:14:46 -080062// 7.2.4. SETTINGS
QUICHE teama6ef0a62019-03-07 20:34:33 -050063//
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
renjietang3b3e3b32019-04-22 18:01:20 -070068using SettingsMap = std::map<uint64_t, uint64_t>;
QUICHE teama6ef0a62019-03-07 20:34:33 -050069
dschinazif25169a2019-10-23 08:12:18 -070070struct QUIC_EXPORT_PRIVATE SettingsFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -050071 SettingsMap values;
72
73 bool operator==(const SettingsFrame& rhs) const {
74 return values == rhs.values;
75 }
renjietang790af402019-06-27 16:52:24 -070076
77 std::string ToString() const {
78 std::string s;
79 for (auto it : values) {
dmcardleba2fb7e2019-12-13 07:44:34 -080080 std::string setting = quiche::QuicheStrCat(
renjietang2db302b2019-09-23 12:40:17 -070081 SpdyUtils::H3SettingsToString(
82 static_cast<Http3AndQpackSettingsIdentifiers>(it.first)),
83 " = ", it.second, "; ");
renjietang790af402019-06-27 16:52:24 -070084 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 teama6ef0a62019-03-07 20:34:33 -050093};
94
bnc94b790c2020-01-10 10:14:46 -080095// 7.2.5. PUSH_PROMISE
QUICHE teama6ef0a62019-03-07 20:34:33 -050096//
97// The PUSH_PROMISE frame (type=0x05) is used to carry a request header
98// set from server to client, as in HTTP/2.
dschinazif25169a2019-10-23 08:12:18 -070099struct QUIC_EXPORT_PRIVATE PushPromiseFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500100 PushId push_id;
dmcardleba2fb7e2019-12-13 07:44:34 -0800101 quiche::QuicheStringPiece headers;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500102
103 bool operator==(const PushPromiseFrame& rhs) const {
104 return push_id == rhs.push_id && headers == rhs.headers;
105 }
106};
107
bnc94b790c2020-01-10 10:14:46 -0800108// 7.2.6. GOAWAY
QUICHE teama6ef0a62019-03-07 20:34:33 -0500109//
110// The GOAWAY frame (type=0x7) is used to initiate graceful shutdown of
111// a connection by a server.
dschinazif25169a2019-10-23 08:12:18 -0700112struct QUIC_EXPORT_PRIVATE GoAwayFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500113 QuicStreamId stream_id;
114
115 bool operator==(const GoAwayFrame& rhs) const {
116 return stream_id == rhs.stream_id;
117 }
118};
119
bnc94b790c2020-01-10 10:14:46 -0800120// 7.2.7. MAX_PUSH_ID
QUICHE teama6ef0a62019-03-07 20:34:33 -0500121//
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.
dschinazif25169a2019-10-23 08:12:18 -0700124struct QUIC_EXPORT_PRIVATE MaxPushIdFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500125 PushId push_id;
126
127 bool operator==(const MaxPushIdFrame& rhs) const {
128 return push_id == rhs.push_id;
129 }
130};
131
bnc94b790c2020-01-10 10:14:46 -0800132// 7.2.8. DUPLICATE_PUSH
QUICHE teama6ef0a62019-03-07 20:34:33 -0500133//
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.
dschinazif25169a2019-10-23 08:12:18 -0700137struct QUIC_EXPORT_PRIVATE DuplicatePushFrame {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500138 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_