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