Qt 6.x
The Qt SDK
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
4#ifndef HTTP2PROTOCOL_P_H
5#define HTTP2PROTOCOL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of the Network Access API. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtNetwork/qnetworkreply.h>
19#include <QtCore/qloggingcategory.h>
20#include <QtCore/qmetatype.h>
21#include <QtCore/private/qglobal_p.h>
22#include <QtCore/qmap.h>
23
24// Different HTTP/2 constants/values as defined by RFC 7540.
25
27
31class QByteArray;
32class QString;
33
34namespace Http2
35{
36
37enum class Settings : quint16
38{
40 ENABLE_PUSH_ID = 0x2,
45};
46
47enum class FrameType : uchar
48{
49 DATA = 0x0,
50 HEADERS = 0x1,
51 PRIORITY = 0x2,
52 RST_STREAM = 0x3,
53 SETTINGS = 0x4,
54 PUSH_PROMISE = 0x5,
55 PING = 0x6,
56 GOAWAY = 0x7,
57 WINDOW_UPDATE = 0x8,
58 CONTINUATION = 0x9,
59 // ATTENTION: enumerators must be sorted.
60 // We use LAST_FRAME_TYPE to check if
61 // frame type is known, if not - this frame
62 // must be ignored, HTTP/2 5.1).
64};
65
66enum class FrameFlag : uchar
67{
68 EMPTY = 0x0, // Valid for any frame type.
69 ACK = 0x1, // Valid for PING, SETTINGS
70 END_STREAM = 0x1, // Valid for HEADERS, DATA
71 END_HEADERS = 0x4, // Valid for PUSH_PROMISE, HEADERS,
72 PADDED = 0x8, // Valid for PUSH_PROMISE, HEADERS, DATA
73 PRIORITY = 0x20 // Valid for HEADERS,
74};
75
76Q_DECLARE_FLAGS(FrameFlags, FrameFlag)
78
80{
81 // Old-style enum, so we
82 // can use as Http2::frameHeaderSize for example.
83 clientPrefaceLength = 24, // HTTP/2, 3.5
84 connectionStreamID = 0, // HTTP/2, 5.1.1
85 frameHeaderSize = 9, // HTTP/2, 4.1
86
87 // The initial allowed payload size. We would use it as an
88 // upper limit for a frame payload we send, until our peer
89 // updates us with a larger SETTINGS_MAX_FRAME_SIZE.
90
91 // The initial maximum payload size that an HTTP/2 frame
92 // can contain is 16384. It's also the minimal size that
93 // can be advertised via 'SETTINGS' frames. A real frame
94 // can have a payload smaller than 16384.
95 minPayloadLimit = 16384, // HTTP/2 6.5.2
96 // The maximum allowed payload size.
97 maxPayloadSize = (1 << 24) - 1, // HTTP/2 6.5.2
98
99 defaultSessionWindowSize = 65535, // HTTP/2 6.5.2
100 maxConcurrentStreams = 100 // HTTP/2, 6.5.2
102
103// These are ints, const, they have internal linkage, it's ok to have them in
104// headers - no ODR violation.
105const quint32 lastValidStreamID((quint32(1) << 31) - 1); // HTTP/2, 5.1.1
106
107// The default size of 64K is too small and limiting: if we use it, we end up
108// sending WINDOW_UPDATE frames on a stream/session all the time, for each
109// 2 DATE frames of size 16K (also default) we'll send a WINDOW_UPDATE frame
110// for a given stream and have a download speed order of magnitude lower than
111// our own HTTP/1.1 protocol handler. We choose a bigger window size: normally,
112// HTTP/2 servers are not afraid to immediately set it to the possible max,
113// we do the same and split this window size between our concurrent streams.
115// Presumably, we never use up to 100 streams so let it be 10 simultaneous:
117
118struct Frame configurationToSettingsFrame(const QHttp2Configuration &configuration);
119QByteArray settingsFrameToBase64(const Frame &settingsFrame);
121
123
124enum class FrameStatus
125{
127 sizeError,
130};
131
133{
134 // Old-style enum to avoid excessive name
135 // qualification ...
136 // NB:
137 // I use the last enumerator to check
138 // that errorCode (quint32) is valid,
139 // so it needs to be the highest-numbered!
140 // HTTP/2 7:
149 CANCEL = 0x8,
156
157void qt_error(quint32 errorCode, QNetworkReply::NetworkError &error, QString &errorString);
161
162} // namespace Http2
163
165
167
168QT_DECL_METATYPE_EXTERN_TAGGED(Http2::Settings, Http2__Settings, Q_NETWORK_EXPORT)
169
170#endif
\inmodule QtCore
Definition qbytearray.h:57
The QHttp2Configuration class controls HTTP/2 parameters and settings.
NetworkError
Indicates all possible error conditions found during the processing of the request.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
Frame configurationToSettingsFrame(const QHttp2Configuration &config)
const char Http2clientPreface[clientPrefaceLength]
bool is_protocol_upgraded(const QHttpNetworkReply &reply)
void appendProtocolUpgradeHeaders(const QHttp2Configuration &config, QHttpNetworkRequest *request)
const quint32 lastValidStreamID((quint32(1)<< 31) - 1)
Http2PredefinedParameters
@ maxConcurrentStreams
@ frameHeaderSize
@ defaultSessionWindowSize
@ connectionStreamID
@ clientPrefaceLength
@ minPayloadLimit
QByteArray settingsFrameToBase64(const Frame &frame)
const qint32 qtDefaultStreamReceiveWindowSize
@ COMPRESSION_ERROR
@ INADEQUATE_SECURITY
@ ENHANCE_YOUR_CALM
@ FLOW_CONTROL_ERROR
@ HTTP_1_1_REQUIRED
void qt_error(quint32 errorCode, QNetworkReply::NetworkError &error, QString &errorMessage)
const qint32 maxSessionReceiveWindowSize((quint32(1)<< 31) - 1)
QString qt_error_string(quint32 errorCode)
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
#define Q_DECLARE_LOGGING_CATEGORY(name)
#define QT_DECL_METATYPE_EXTERN_TAGGED(TYPE, TAG, EXPORT)
Definition qmetatype.h:1355
#define Q_AUTOTEST_EXPORT
unsigned int quint32
Definition qtypes.h:45
unsigned char uchar
Definition qtypes.h:27
unsigned short quint16
Definition qtypes.h:43
int qint32
Definition qtypes.h:44
QNetworkRequest request(url)
QNetworkReply * reply