Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qhttp2configuration.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 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
5
6#include "private/http2protocol_p.h"
7#include "private/hpack_p.h"
8
9#include "qdebug.h"
10
12
13/*!
14 \class QHttp2Configuration
15 \brief The QHttp2Configuration class controls HTTP/2 parameters and settings.
16 \since 5.14
17
18 \reentrant
19 \inmodule QtNetwork
20 \ingroup network
21 \ingroup shared
22
23 QHttp2Configuration controls HTTP/2 parameters and settings that
24 QNetworkAccessManager will use to send requests and process responses
25 when the HTTP/2 protocol is enabled.
26
27 The HTTP/2 parameters that QHttp2Configuration currently supports include:
28
29 \list
30 \li The session window size for connection-level flow control.
31 Will be sent to a remote peer when needed as 'WINDOW_UPDATE'
32 frames on the stream with an identifier 0.
33 \li The stream receiving window size for stream-level flow control.
34 Sent as 'SETTINGS_INITIAL_WINDOW_SIZE' parameter in the initial
35 SETTINGS frame and, when needed, 'WINDOW_UPDATE' frames will be
36 sent on streams that QNetworkAccessManager opens.
37 \li The maximum frame size. This parameter limits the maximum payload
38 a frame coming from the remote peer can have. Sent by QNetworkAccessManager
39 as 'SETTINGS_MAX_FRAME_SIZE' parameter in the initial 'SETTINGS'
40 frame.
41 \li The server push. Allows to enable or disable server push. Sent
42 as 'SETTINGS_ENABLE_PUSH' parameter in the initial 'SETTINGS'
43 frame.
44 \endlist
45
46 The QHttp2Configuration class also controls if the header compression
47 algorithm (HPACK) is additionally using Huffman coding for string
48 compression.
49
50 \note The configuration must be set before the first request
51 was sent to a given host (and thus an HTTP/2 session established).
52
53 \note Details about flow control, server push and 'SETTINGS'
54 can be found in \l {https://httpwg.org/specs/rfc7540.html}{RFC 7540}.
55 Different modes and parameters of the HPACK compression algorithm
56 are described in \l {https://httpwg.org/specs/rfc7541.html}{RFC 7541}.
57
58 \sa QNetworkRequest::setHttp2Configuration(), QNetworkRequest::http2Configuration(), QNetworkAccessManager
59*/
60
62{
63public:
66
67 unsigned maxFrameSize = Http2::minPayloadLimit; // Initial (default) value of 16Kb.
68
70
71 bool pushEnabled = false;
72 // TODO: for now those two below are noop.
74};
75
76/*!
77 Default constructs a QHttp2Configuration object.
78
79 Such a configuration has the following values:
80 \list
81 \li Server push is disabled
82 \li Huffman string compression is enabled
83 \li Window size for connection-level flow control is 65535 octets
84 \li Window size for stream-level flow control is 65535 octets
85 \li Frame size is 16384 octets
86 \endlist
87*/
88QHttp2Configuration::QHttp2Configuration()
89 : d(new QHttp2ConfigurationPrivate)
90{
91}
92
93/*!
94 Copy-constructs this QHttp2Configuration.
95*/
96QHttp2Configuration::QHttp2Configuration(const QHttp2Configuration &) = default;
97
98/*!
99 Move-constructs this QHttp2Configuration from \a other
100*/
101QHttp2Configuration::QHttp2Configuration(QHttp2Configuration &&other) noexcept
102{
103 swap(other);
104}
105
106/*!
107 Copy-assigns \a other to this QHttp2Configuration.
108*/
109QHttp2Configuration &QHttp2Configuration::operator=(const QHttp2Configuration &) = default;
110
111/*!
112 Move-assigns \a other to this QHttp2Configuration.
113*/
114QHttp2Configuration &QHttp2Configuration::operator=(QHttp2Configuration &&) noexcept = default;
115
116/*!
117 Destructor.
118*/
119QHttp2Configuration::~QHttp2Configuration()
120{
121}
122
123/*!
124 If \a enable is \c true, a remote server can potentially
125 use server push to send responses in advance.
126
127 \sa serverPushEnabled
128*/
129void QHttp2Configuration::setServerPushEnabled(bool enable)
130{
131 d->pushEnabled = enable;
132}
133
134/*!
135 Returns true if server push was enabled.
136
137 \note By default, QNetworkAccessManager disables server
138 push via the 'SETTINGS' frame.
139
140 \sa setServerPushEnabled
141*/
142bool QHttp2Configuration::serverPushEnabled() const
143{
144 return d->pushEnabled;
145}
146
147/*!
148 If \a enable is \c true, HPACK compression will additionally
149 compress string using the Huffman coding. Enabled by default.
150
151 \note This parameter only affects 'HEADERS' frames that
152 QNetworkAccessManager is sending.
153
154 \sa huffmanCompressionEnabled
155*/
156void QHttp2Configuration::setHuffmanCompressionEnabled(bool enable)
157{
158 d->huffmanCompressionEnabled = enable;
159}
160
161/*!
162 Returns \c true if the Huffman coding in HPACK is enabled.
163
164 \sa setHuffmanCompressionEnabled
165*/
166bool QHttp2Configuration::huffmanCompressionEnabled() const
167{
168 return d->huffmanCompressionEnabled;
169}
170
171/*!
172 Sets the window size for connection-level flow control.
173 \a size cannot be 0 and must not exceed 2147483647 octets.
174
175 Returns \c true on success, \c false otherwise.
176
177 \sa sessionReceiveWindowSize
178*/
179bool QHttp2Configuration::setSessionReceiveWindowSize(unsigned size)
180{
181 if (!size || size > Http2::maxSessionReceiveWindowSize) { // RFC-7540, 6.9
182 qCWarning(QT_HTTP2) << "Invalid session window size";
183 return false;
184 }
185
186 d->sessionWindowSize = size;
187 return true;
188}
189
190/*!
191 Returns the window size for connection-level flow control.
192 The default value QNetworkAccessManager will be using is
193 2147483647 octets.
194*/
195unsigned QHttp2Configuration::sessionReceiveWindowSize() const
196{
197 return d->sessionWindowSize;
198}
199
200/*!
201 Sets the window size for stream-level flow control.
202 \a size cannot be 0 and must not exceed 2147483647 octets.
203
204 Returns \c true on success, \c false otherwise.
205
206 \sa streamReceiveWindowSize
207 */
208bool QHttp2Configuration::setStreamReceiveWindowSize(unsigned size)
209{
210 if (!size || size > Http2::maxSessionReceiveWindowSize) { // RFC-7540, 6.9
211 qCWarning(QT_HTTP2) << "Invalid stream window size";
212 return false;
213 }
214
215 d->streamWindowSize = size;
216 return true;
217}
218
219/*!
220 Returns the window size for stream-level flow control.
221 The default value QNetworkAccessManager will be using is
222 214748364 octets (see \l {https://httpwg.org/specs/rfc7540.html#SettingValues}{RFC 7540}).
223*/
224unsigned QHttp2Configuration::streamReceiveWindowSize() const
225{
226 return d->streamWindowSize;
227}
228
229/*!
230 Sets the maximum frame size that QNetworkAccessManager
231 will advertise to the server when sending its initial SETTINGS frame.
232 \note While this \a size is required to be within a range between
233 16384 and 16777215 inclusive, the actual payload size in frames
234 that carry payload maybe be less than 16384.
235
236 Returns \c true on success, \c false otherwise.
237*/
238bool QHttp2Configuration::setMaxFrameSize(unsigned size)
239{
240 if (size < Http2::minPayloadLimit || size > Http2::maxPayloadSize) {
241 qCWarning(QT_HTTP2) << "Maximum frame size to advertise is invalid";
242 return false;
243 }
244
245 d->maxFrameSize = size;
246 return true;
247}
248
249/*!
250 Returns the maximum payload size that HTTP/2 frames can
251 have. The default (initial) value is 16384 octets.
252*/
253unsigned QHttp2Configuration::maxFrameSize() const
254{
255 return d->maxFrameSize;
256}
257
258/*!
259 \since 6.9
260
261 Sets \a value as the maximum number of concurrent streams that
262 will be advertised to the peer when sending SETTINGS frame.
263
264 \sa maxConcurrentStreams()
265*/
266void QHttp2Configuration::setMaxConcurrentStreams(unsigned value)
267{
268 d->maxConcurrentStreams = value;
269}
270
271/*!
272 \since 6.9
273
274 Returns the maximum number of concurrent streams.
275
276 \sa setMaxConcurrentStreams()
277*/
278unsigned QHttp2Configuration::maxConcurrentStreams() const
279{
280 return d->maxConcurrentStreams;
281}
282
283/*!
284 \memberswap{configuration}
285*/
286void QHttp2Configuration::swap(QHttp2Configuration &other) noexcept
287{
288 d.swap(other.d);
289}
290
291/*!
292 \fn bool QHttp2Configuration::operator==(const QHttp2Configuration &lhs, const QHttp2Configuration &rhs) noexcept
293 Returns \c true if \a lhs and \a rhs have the same set of HTTP/2
294 parameters.
295*/
296
297/*!
298 \fn bool QHttp2Configuration::operator!=(const QHttp2Configuration &lhs, const QHttp2Configuration &rhs) noexcept
299 Returns \c true if \a lhs and \a rhs do not have the same set of HTTP/2
300 parameters.
301*/
302
303/*!
304 \internal
305*/
306bool QHttp2Configuration::isEqual(const QHttp2Configuration &other) const noexcept
307{
308 if (d == other.d)
309 return true;
310
311 return d->pushEnabled == other.d->pushEnabled
312 && d->huffmanCompressionEnabled == other.d->huffmanCompressionEnabled
313 && d->sessionWindowSize == other.d->sessionWindowSize
314 && d->streamWindowSize == other.d->streamWindowSize
315 && d->maxConcurrentStreams == other.d->maxConcurrentStreams;
316}
317
318QT_END_NAMESPACE
Combined button and popup list for selecting options.