1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "qhttpserverconfiguration.h"
QT_BEGIN_NAMESPACE
/*!
\class QHttpServerConfiguration
\since 6.9
\inmodule QtHttpServer
\brief The QHttpServerConfiguration class controls server parameters.
*/
class QHttpServerConfigurationPrivate : public QSharedData
{
public:
quint32 rateLimit = 0;
std::chrono::seconds keepAliveTimeout = std::chrono::seconds(15);
QList<QPair<QHostAddress, int>> whitelist;
QList<QPair<QHostAddress, int>> blacklist;
};
QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QHttpServerConfigurationPrivate)
/*!
Default constructs a QHttpServerConfiguration object.
Such a configuration has the following values:
\list
\li Rate limit is disabled
\endlist
*/
QHttpServerConfiguration::QHttpServerConfiguration()
: d(new QHttpServerConfigurationPrivate)
{
}
/*!
Copy-constructs this QHttpServerConfiguration.
*/
QHttpServerConfiguration::QHttpServerConfiguration(const QHttpServerConfiguration &) = default;
/*!
\fn QHttpServerConfiguration::QHttpServerConfiguration(QHttpServerConfiguration &&other) noexcept
Move-constructs this QHttpServerConfiguration from \a other
*/
/*!
Copy-assigns \a other to this QHttpServerConfiguration.
*/
QHttpServerConfiguration &QHttpServerConfiguration::operator=(const QHttpServerConfiguration &) = default;
/*!
\fn QHttpServerConfiguration &QHttpServerConfiguration::operator=(QHttpServerConfiguration &&other) noexcept
Move-assigns \a other to this QHttpServerConfiguration.
*/
/*!
Destructor.
*/
QHttpServerConfiguration::~QHttpServerConfiguration()
= default;
/*!
Sets \a maxRequests as the maximum number of incoming requests
per second per IP that will be accepted by QHttpServer.
If the limit is exceeded, QHttpServer will respond with
QHttpServerResponder::StatusCode::TooManyRequests.
\sa rateLimitPerSecond(), QHttpServerResponder::StatusCode
*/
void QHttpServerConfiguration::setRateLimitPerSecond(quint32 maxRequests)
{
d.detach();
d->rateLimit = maxRequests;
}
/*!
Returns maximum number of incoming requests per second per IP
accepted by the server.
\sa setRateLimitPerSecond()
*/
quint32 QHttpServerConfiguration::rateLimitPerSecond() const
{
return d->rateLimit;
}
/*!
\since 6.10
Sets \a timeout as keep-alive timeout for QHttpServer.
The keep-alive timeout determines how long an idle connection is kept
open before being closed.
By default, the timeout is set to 15 seconds.
\sa keepAliveTimeout()
*/
void QHttpServerConfiguration::setKeepAliveTimeout(std::chrono::seconds timeout)
{
d.detach();
d->keepAliveTimeout = timeout;
}
/*!
\since 6.10
Returns the keep-alive timeout used by QHttpServer.
\sa setKeepAliveTimeout()
*/
std::chrono::seconds QHttpServerConfiguration::keepAliveTimeout() const
{
return d->keepAliveTimeout;
}
/*!
Sets \a subnetList as the whitelist of allowed subnets.
When the list is not empty, only IP addresses in this list
will be allowed by QHttpServer. The whitelist takes priority
over the blacklist.
Each subnet is represented as a pair consisting of:
\list
\li A base IP address of type QHostAddress.
\li A CIDR prefix length of type int, which defines the subnet mask.
\endlist
To allow only a specific IP address, use a prefix length of 32 for IPv4
(e.g., \c "192.168.1.100/32") or 128 for IPv6 (e.g., \c "2001:db8::1/128").
\sa whitelist(), setBlacklist(), QHostAddress::parseSubnet()
*/
void QHttpServerConfiguration::setWhitelist(const QList<std::pair<QHostAddress, int>> &subnetList)
{
d.detach();
d->whitelist = subnetList;
}
/*!
Returns the whitelist of subnets allowed by QHttpServer.
\sa setWhitelist()
*/
QList<std::pair<QHostAddress, int>> QHttpServerConfiguration::whitelist() const
{
return d->whitelist;
}
/*!
Sets \a subnetList as the blacklist of subnets.
IP addresses in this list will be denied access by QHttpServer.
The blacklist is active only when the whitelist is empty.
\sa blacklist(), setWhitelist(), QHostAddress::parseSubnet()
*/
void QHttpServerConfiguration::setBlacklist(const QList<std::pair<QHostAddress, int>> &subnetList)
{
d.detach();
d->blacklist = subnetList;
}
/*!
Returns the blacklist of subnets that are denied access by QHttpServer.
\sa setBlacklist()
*/
QList<std::pair<QHostAddress, int>> QHttpServerConfiguration::blacklist() const
{
return d->blacklist;
}
/*!
\fn void QHttpServerConfiguration::swap(QHttpServerConfiguration &other)
\memberswap{configuration}
*/
/*!
\fn bool QHttpServerConfiguration::operator==(const QHttpServerConfiguration &lhs, const QHttpServerConfiguration &rhs) noexcept
Returns \c true if \a lhs and \a rhs have the same set of configuration
parameters.
*/
/*!
\fn bool QHttpServerConfiguration::operator!=(const QHttpServerConfiguration &lhs, const QHttpServerConfiguration &rhs) noexcept
Returns \c true if \a lhs and \a rhs do not have the same set of configuration
parameters.
*/
/*!
\internal
*/
bool comparesEqual(const QHttpServerConfiguration &lhs, const QHttpServerConfiguration &rhs) noexcept
{
if (lhs.d == rhs.d)
return true;
return lhs.d->rateLimit == rhs.d->rateLimit;
}
QT_END_NAMESPACE
|