QHttpServerConfiguration Class

QHttpServerConfiguration 类控制服务器参数。更多

头文件: #include <QHttpServerConfiguration>
CMake: find_package(Qt6 REQUIRED COMPONENTS HttpServer)
target_link_libraries(mytarget PRIVATE Qt6::HttpServer)
qmake: QT += httpserver
Qt 6.9

公共函数

QHttpServerConfiguration()
QHttpServerConfiguration(const QHttpServerConfiguration &other)
QHttpServerConfiguration(QHttpServerConfiguration &&other)
~QHttpServerConfiguration()
(since 6.10) QSpan<const std::pair<QHostAddress, int>> blacklist() const
(since 6.10) std::chrono::seconds keepAliveTimeout() const
quint32 rateLimitPerSecond() const
(since 6.10) void setBlacklist(QSpan<const std::pair<QHostAddress, int>> subnetList)
(since 6.10) void setKeepAliveTimeout(std::chrono::seconds timeout)
void setRateLimitPerSecond(quint32 maxRequests)
(since 6.10) void setWhitelist(QSpan<const std::pair<QHostAddress, int>> subnetList)
void swap(QHttpServerConfiguration &other)
(since 6.10) QSpan<const std::pair<QHostAddress, int>> whitelist() const
QHttpServerConfiguration &operator=(QHttpServerConfiguration &&other)
QHttpServerConfiguration &operator=(const QHttpServerConfiguration &other)
bool operator!=(const QHttpServerConfiguration &lhs, const QHttpServerConfiguration &rhs)
bool operator==(const QHttpServerConfiguration &lhs, const QHttpServerConfiguration &rhs)

详细说明

成员函数文档

QHttpServerConfiguration::QHttpServerConfiguration()

Default 构造一个 QHttpServerConfiguration 对象。

该配置具有以下值:

  • 禁用速率限制

QHttpServerConfiguration::QHttpServerConfiguration(const QHttpServerConfiguration &other)

复制-构建此 QHttpServerConfiguration。

[noexcept] QHttpServerConfiguration::QHttpServerConfiguration(QHttpServerConfiguration &&other)

Move-construct this QHttpServerConfiguration fromother

[noexcept] QHttpServerConfiguration::~QHttpServerConfiguration()

毁灭者

[since 6.10] QSpan<const std::pair<QHostAddress, int>> QHttpServerConfiguration::blacklist() const

返回被QHttpServer 拒绝访问的子网黑名单。

此函数在 Qt 6.10 中引入。

另请参阅 setBlacklist()。

[since 6.10] std::chrono::seconds QHttpServerConfiguration::keepAliveTimeout() const

返回QHttpServer 使用的保持连接超时。

此函数在 Qt 6.10 中引入。

另请参阅 setKeepAliveTimeout() 。

quint32 QHttpServerConfiguration::rateLimitPerSecond() const

返回服务器每个 IP 每秒接受的最大传入请求数。

另请参阅 setRateLimitPerSecond()。

[since 6.10] void QHttpServerConfiguration::setBlacklist(QSpan<const std::pair<QHostAddress, int>> subnetList)

subnetList 设置为子网黑名单。

QHttpServer 将拒绝访问该列表中的 IP 地址。只有当白名单为空时,黑名单才会激活。

此函数在 Qt 6.10 中引入。

另请参阅 blacklist()、setWhitelist() 和QHostAddress::parseSubnet()。

[since 6.10] void QHttpServerConfiguration::setKeepAliveTimeout(std::chrono::seconds timeout)

timeout 设置为QHttpServer 的保持连接超时。

保持连接超时决定了空闲连接在关闭前的开放时间。默认情况下,超时设置为 15 秒。

该函数在 Qt 6.10 中引入。

另请参阅 keepAliveTimeout() 。

void QHttpServerConfiguration::setRateLimitPerSecond(quint32 maxRequests)

maxRequests 设置为QHttpServer 每 IP 每秒可接受的最大传入请求数。如果超过限制,QHttpServer 将以QHttpServerResponder::StatusCode::TooManyRequests 回应。

另请参阅 rateLimitPerSecond() 和QHttpServerResponder::StatusCode

[since 6.10] void QHttpServerConfiguration::setWhitelist(QSpan<const std::pair<QHostAddress, int>> subnetList)

subnetList 设置为允许子网的白名单。

当该列表不为空时,QHttpServer 只允许使用该列表中的 IP 地址。白名单优先于黑名单。

每个子网都是一对,包括

  • 类型为QHostAddress 的基础 IP 地址。
  • 类型为 int 的 CIDR 前缀长度,定义子网掩码。

要只允许使用特定的 IP 地址,IPv4 的前缀长度应为 32(如"192.168.1.100/32" ),IPv6 的前缀长度应为 128(如"2001:db8::1/128" )。

此功能在 Qt 6.10 中引入。

另请参阅 whitelist()、setBlacklist() 和QHostAddress::parseSubnet()。

[noexcept] void QHttpServerConfiguration::swap(QHttpServerConfiguration &other)

将此配置与other 互换。这一操作非常快速,从未出现过故障。

[since 6.10] QSpan<const std::pair<QHostAddress, int>> QHttpServerConfiguration::whitelist() const

返回QHttpServer 允许使用的子网白名单。

此函数在 Qt 6.10 中引入。

另请参阅 setWhitelist()。

[noexcept] QHttpServerConfiguration &QHttpServerConfiguration::operator=(QHttpServerConfiguration &&other)

移动--将other 分配到此QHttpServerConfiguration

QHttpServerConfiguration &QHttpServerConfiguration::operator=(const QHttpServerConfiguration &other)

复制分配otherQHttpServerConfiguration

相关非会员

[noexcept] bool operator!=(const QHttpServerConfiguration &lhs, const QHttpServerConfiguration &rhs)

如果lhsrhs 的配置参数集不同,则返回true

[noexcept] bool operator==(const QHttpServerConfiguration &lhs, const QHttpServerConfiguration &rhs)

如果lhsrhs 具有相同的配置参数集,则返回true

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.