Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
http2protocol_p.h
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
ifndef
HTTP2PROTOCOL_P_H
6
#
define
HTTP2PROTOCOL_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists for the convenience
13
// of the Network Access API. This header file may change from
14
// version to version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
QtNetwork
/
qnetworkreply
.
h
>
20
#
include
<
QtCore
/
qloggingcategory
.
h
>
21
#
include
<
QtCore
/
qmetatype
.
h
>
22
#
include
<
QtCore
/
qmap
.
h
>
23
24
#
include
<
vector
>
25
26
// Different HTTP/2 constants/values as defined by RFC 7540.
27
28
QT_BEGIN_NAMESPACE
29
30
class
QHttpNetworkRequest;
31
class
QHttp2Configuration;
32
class
QHttpNetworkReply;
33
class
QByteArray
;
34
class
QString;
35
36
namespace
Http2
37
{
38
39
enum
class
Settings
:
quint16
40
{
41
HEADER_TABLE_SIZE_ID
= 0x1,
42
ENABLE_PUSH_ID
= 0x2,
43
MAX_CONCURRENT_STREAMS_ID
= 0x3,
44
INITIAL_WINDOW_SIZE_ID
= 0x4,
45
MAX_FRAME_SIZE_ID
= 0x5,
46
MAX_HEADER_LIST_SIZE_ID
= 0x6
47
};
48
49
enum
class
FrameType
:
uchar
50
{
51
DATA
= 0x0,
52
HEADERS
= 0x1,
53
PRIORITY
= 0x2,
54
RST_STREAM
= 0x3,
55
SETTINGS
= 0x4,
56
PUSH_PROMISE
= 0x5,
57
PING
= 0x6,
58
GOAWAY
= 0x7,
59
WINDOW_UPDATE
= 0x8,
60
CONTINUATION
= 0x9,
61
// ATTENTION: enumerators must be sorted.
62
// We use LAST_FRAME_TYPE to check if
63
// frame type is known, if not - this frame
64
// must be ignored, HTTP/2 5.1).
65
LAST_FRAME_TYPE
66
};
67
68
enum
class
FrameFlag
:
uchar
69
{
70
EMPTY
= 0x0,
// Valid for any frame type.
71
ACK
= 0x1,
// Valid for PING, SETTINGS
72
END_STREAM
= 0x1,
// Valid for HEADERS, DATA
73
END_HEADERS
= 0x4,
// Valid for PUSH_PROMISE, HEADERS,
74
PADDED
= 0x8,
// Valid for PUSH_PROMISE, HEADERS, DATA
75
PRIORITY
= 0x20
// Valid for HEADERS,
76
};
77
78
Q_DECLARE_FLAGS
(
FrameFlags
,
FrameFlag
)
79
Q_DECLARE_OPERATORS_FOR_FLAGS
(
FrameFlags
)
80
81
enum
Http2PredefinedParameters
82
{
83
// Old-style enum, so we
84
// can use as Http2::frameHeaderSize for example.
85
clientPrefaceLength
= 24,
// HTTP/2, 3.5
86
connectionStreamID
= 0,
// HTTP/2, 5.1.1
87
frameHeaderSize
= 9,
// HTTP/2, 4.1
88
89
// The initial allowed payload size. We would use it as an
90
// upper limit for a frame payload we send, until our peer
91
// updates us with a larger SETTINGS_MAX_FRAME_SIZE.
92
93
// The initial maximum payload size that an HTTP/2 frame
94
// can contain is 16384. It's also the minimal size that
95
// can be advertised via 'SETTINGS' frames. A real frame
96
// can have a payload smaller than 16384.
97
minPayloadLimit
= 16384,
// HTTP/2 6.5.2
98
// The maximum allowed payload size.
99
maxPayloadSize
= (1 << 24) - 1,
// HTTP/2 6.5.2
100
101
defaultSessionWindowSize
= 65535,
// HTTP/2 6.5.2
102
maxConcurrentStreams
= 100
// HTTP/2, 6.5.2
103
};
104
105
// These are ints, const, they have internal linkage, it's ok to have them in
106
// headers - no ODR violation.
107
const
quint32
lastValidStreamID
((quint32(1) << 31) - 1);
// HTTP/2, 5.1.1
108
109
// The default size of 64K is too small and limiting: if we use it, we end up
110
// sending WINDOW_UPDATE frames on a stream/session all the time, for each
111
// 2 DATE frames of size 16K (also default) we'll send a WINDOW_UPDATE frame
112
// for a given stream and have a download speed order of magnitude lower than
113
// our own HTTP/1.1 protocol handler. We choose a bigger window size: normally,
114
// HTTP/2 servers are not afraid to immediately set it to the possible max,
115
// we do the same and split this window size between our concurrent streams.
116
const
qint32
maxSessionReceiveWindowSize
((quint32(1) << 31) - 1);
117
// Presumably, we never use up to 100 streams so let it be 10 simultaneous:
118
const
qint32
qtDefaultStreamReceiveWindowSize
= maxSessionReceiveWindowSize / 10;
119
120
struct
Frame Q_AUTOTEST_EXPORT
configurationToSettingsFrame
(
const
QHttp2Configuration
&
configuration
);
121
QByteArray
settingsFrameToBase64(
const
Frame &settingsFrame);
122
void
appendProtocolUpgradeHeaders(
const
QHttp2Configuration &configuration, QHttpNetworkRequest *request);
123
std::vector<uchar> assemble_hpack_block(
const
std::vector<Frame> &frames);
124
125
extern
const
Q_AUTOTEST_EXPORT
char
Http2clientPreface[
clientPrefaceLength
];
126
127
enum
class
FrameStatus
128
{
129
protocolError
,
130
sizeError
,
131
incompleteFrame
,
132
goodFrame
133
};
134
135
enum
Http2Error
:
quint32
136
{
137
// Old-style enum to avoid excessive name
138
// qualification ...
139
// NB:
140
// I use the last enumerator to check
141
// that errorCode (quint32) is valid,
142
// so it needs to be the highest-numbered!
143
// HTTP/2 7:
144
HTTP2_NO_ERROR
= 0x0,
145
PROTOCOL_ERROR
= 0x1,
146
INTERNAL_ERROR
= 0x2,
147
FLOW_CONTROL_ERROR
= 0x3,
148
SETTINGS_TIMEOUT
= 0x4,
149
STREAM_CLOSED
= 0x5,
150
FRAME_SIZE_ERROR
= 0x6,
151
REFUSE_STREAM
= 0x7,
152
CANCEL
= 0x8,
153
COMPRESSION_ERROR
= 0x9,
154
CONNECT_ERROR
= 0xa,
155
ENHANCE_YOUR_CALM
= 0xb,
156
INADEQUATE_SECURITY
= 0xc,
157
HTTP_1_1_REQUIRED
= 0xd
158
};
159
160
void
qt_error(quint32 errorCode, QNetworkReply::NetworkError &error, QString &errorString);
161
QString qt_error_string(quint32 errorCode);
162
QNetworkReply::NetworkError qt_error(quint32 errorCode);
163
bool
is_protocol_upgraded(
const
QHttpNetworkReply &reply);
164
165
}
// namespace Http2
166
167
Q_DECLARE_LOGGING_CATEGORY(QT_HTTP2)
168
169
QT_END_NAMESPACE
170
171
QT_DECL_METATYPE_EXTERN_TAGGED(Http2::Settings, Http2__Settings, Q_NETWORK_EXPORT)
172
173
#
endif
Http2::FrameReader
Definition
http2frames_p.h:67
Http2::FrameWriter
Definition
http2frames_p.h:85
QByteArray::FromBase64Result
\inmodule QtCore
Definition
qbytearray.h:824
Http2
Definition
http2frames.cpp:15
Http2::FrameType
FrameType
Definition
http2protocol_p.h:50
Http2::FrameType::HEADERS
@ HEADERS
Definition
http2protocol_p.h:52
Http2::FrameType::GOAWAY
@ GOAWAY
Definition
http2protocol_p.h:58
Http2::FrameType::LAST_FRAME_TYPE
@ LAST_FRAME_TYPE
Definition
http2protocol_p.h:65
Http2::FrameType::WINDOW_UPDATE
@ WINDOW_UPDATE
Definition
http2protocol_p.h:59
Http2::FrameType::PUSH_PROMISE
@ PUSH_PROMISE
Definition
http2protocol_p.h:56
Http2::FrameType::CONTINUATION
@ CONTINUATION
Definition
http2protocol_p.h:60
Http2::FrameType::RST_STREAM
@ RST_STREAM
Definition
http2protocol_p.h:54
Http2::FrameType::PRIORITY
@ PRIORITY
Definition
http2protocol_p.h:53
Http2::FrameType::PING
@ PING
Definition
http2protocol_p.h:57
Http2::FrameType::DATA
@ DATA
Definition
http2protocol_p.h:51
Http2::FrameType::SETTINGS
@ SETTINGS
Definition
http2protocol_p.h:55
Http2::FrameFlag
FrameFlag
Definition
http2protocol_p.h:69
Http2::FrameFlag::ACK
@ ACK
Definition
http2protocol_p.h:71
Http2::FrameFlag::PADDED
@ PADDED
Definition
http2protocol_p.h:74
Http2::FrameFlag::END_STREAM
@ END_STREAM
Definition
http2protocol_p.h:72
Http2::FrameFlag::EMPTY
@ EMPTY
Definition
http2protocol_p.h:70
Http2::FrameFlag::PRIORITY
@ PRIORITY
Definition
http2protocol_p.h:75
Http2::FrameFlag::END_HEADERS
@ END_HEADERS
Definition
http2protocol_p.h:73
Http2::FrameStatus
FrameStatus
Definition
http2protocol_p.h:128
Http2::FrameStatus::protocolError
@ protocolError
Definition
http2protocol_p.h:129
Http2::FrameStatus::incompleteFrame
@ incompleteFrame
Definition
http2protocol_p.h:131
Http2::FrameStatus::goodFrame
@ goodFrame
Definition
http2protocol_p.h:132
Http2::FrameStatus::sizeError
@ sizeError
Definition
http2protocol_p.h:130
Http2::Http2Error
Http2Error
Definition
http2protocol_p.h:136
Http2::COMPRESSION_ERROR
@ COMPRESSION_ERROR
Definition
http2protocol_p.h:153
Http2::PROTOCOL_ERROR
@ PROTOCOL_ERROR
Definition
http2protocol_p.h:145
Http2::INADEQUATE_SECURITY
@ INADEQUATE_SECURITY
Definition
http2protocol_p.h:156
Http2::REFUSE_STREAM
@ REFUSE_STREAM
Definition
http2protocol_p.h:151
Http2::ENHANCE_YOUR_CALM
@ ENHANCE_YOUR_CALM
Definition
http2protocol_p.h:155
Http2::CONNECT_ERROR
@ CONNECT_ERROR
Definition
http2protocol_p.h:154
Http2::SETTINGS_TIMEOUT
@ SETTINGS_TIMEOUT
Definition
http2protocol_p.h:148
Http2::STREAM_CLOSED
@ STREAM_CLOSED
Definition
http2protocol_p.h:149
Http2::HTTP2_NO_ERROR
@ HTTP2_NO_ERROR
Definition
http2protocol_p.h:144
Http2::CANCEL
@ CANCEL
Definition
http2protocol_p.h:152
Http2::FLOW_CONTROL_ERROR
@ FLOW_CONTROL_ERROR
Definition
http2protocol_p.h:147
Http2::HTTP_1_1_REQUIRED
@ HTTP_1_1_REQUIRED
Definition
http2protocol_p.h:157
Http2::FRAME_SIZE_ERROR
@ FRAME_SIZE_ERROR
Definition
http2protocol_p.h:150
Http2::INTERNAL_ERROR
@ INTERNAL_ERROR
Definition
http2protocol_p.h:146
Http2::lastValidStreamID
const quint32 lastValidStreamID((quint32(1)<< 31) - 1)
Http2::qtDefaultStreamReceiveWindowSize
const qint32 qtDefaultStreamReceiveWindowSize
Definition
http2protocol_p.h:118
Http2::Settings
Settings
Definition
http2protocol_p.h:40
Http2::Settings::MAX_CONCURRENT_STREAMS_ID
@ MAX_CONCURRENT_STREAMS_ID
Definition
http2protocol_p.h:43
Http2::Settings::INITIAL_WINDOW_SIZE_ID
@ INITIAL_WINDOW_SIZE_ID
Definition
http2protocol_p.h:44
Http2::Settings::MAX_HEADER_LIST_SIZE_ID
@ MAX_HEADER_LIST_SIZE_ID
Definition
http2protocol_p.h:46
Http2::Settings::MAX_FRAME_SIZE_ID
@ MAX_FRAME_SIZE_ID
Definition
http2protocol_p.h:45
Http2::Settings::HEADER_TABLE_SIZE_ID
@ HEADER_TABLE_SIZE_ID
Definition
http2protocol_p.h:41
Http2::Settings::ENABLE_PUSH_ID
@ ENABLE_PUSH_ID
Definition
http2protocol_p.h:42
Http2::maxSessionReceiveWindowSize
const qint32 maxSessionReceiveWindowSize((quint32(1)<< 31) - 1)
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
Http2::Frame
Definition
http2frames_p.h:35
Http2::Frame::validateHeader
FrameStatus validateHeader() const
Definition
http2frames.cpp:105
Http2::Frame::priority
bool priority(quint32 *streamID=nullptr, uchar *weight=nullptr) const
Definition
http2frames.cpp:82
Http2::Frame::validatePayload
FrameStatus validatePayload() const
Definition
http2frames.cpp:162
Http2::Frame::supportsPaddedFlag
bool supportsPaddedFlag() const
Definition
http2frames.cpp:69
Http2::Frame::padding
uchar padding() const
Definition
http2frames.cpp:53
Http2::Frame::dataBegin
const uchar * dataBegin() const
Definition
http2frames.cpp:246
Http2::Frame::hpackBlockSize
quint32 hpackBlockSize() const
Definition
http2frames.cpp:228
Http2::Frame::payloadSize
quint32 payloadSize() const
Definition
http2frames.cpp:47
Http2::Frame::streamID
quint32 streamID() const
Definition
http2frames.cpp:34
Http2::Frame::dataSize
quint32 dataSize() const
Definition
http2frames.cpp:211
Http2::Frame::hpackBlockBegin
const uchar * hpackBlockBegin() const
Definition
http2frames.cpp:262
Http2::Frame::isPadded
bool isPadded() const
Definition
http2frames.cpp:64
Http2::Frame::buffer
std::vector< uchar > buffer
Definition
http2frames_p.h:63
Http2::Frame::type
FrameType type() const
Definition
http2frames.cpp:24
Http2::Frame::flags
FrameFlags flags() const
Definition
http2frames.cpp:41
qtbase
src
network
access
http2
http2protocol_p.h
Generated on
for Qt by
1.18.0