- Qt 6.12
- Qt HTTP Server
- C++ Classes
- QHttpServerConfiguration
- Qt 6.12.0 Reference Documentation

# QHttpServerConfiguration Class

The QHttpServerConfiguration class controls server parameters. More...

Header: | `#include <QHttpServerConfiguration>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS HttpServer)` `target_link_libraries(mytarget PRIVATE Qt6::HttpServer)`
qmake: | `QT += httpserver`
Since: | Qt 6.9

- List of all members, including inherited members

## Public Functions

| 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
`(since 6.11)` qint64 | maximumBodySize() const
`(since 6.12)` quint32 | maximumConnections() const
`(since 6.12)` quint32 | maximumConnectionsPerHost() const
`(since 6.11)` qint64 | maximumHeaderFieldCount() const
`(since 6.11)` qint64 | maximumHeaderFieldSize() const
`(since 6.11)` qint64 | maximumTotalHeaderSize() const
`(since 6.11)` qint64 | maximumUrlSize() 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)
`(since 6.11)` void | setMaximumBodySize(qint64 maxSize)
`(since 6.12)` void | setMaximumConnections(quint32 maxConnections)
`(since 6.12)` void | setMaximumConnectionsPerHost(quint32 maxConnections)
`(since 6.11)` void | setMaximumHeaderFieldCount(qint64 maxSize)
`(since 6.11)` void | setMaximumHeaderFieldSize(qint64 maxSize)
`(since 6.11)` void | setMaximumTotalHeaderSize(qint64 maxSize)
`(since 6.11)` void | setMaximumUrlSize(qint64 maxSize)
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)

## Related Non-Members

bool | operator!=(const QHttpServerConfiguration &lhs, const QHttpServerConfiguration &rhs)
bool | operator==(const QHttpServerConfiguration &lhs, const QHttpServerConfiguration &rhs)

## Detailed Description

## Member Function Documentation

### QHttpServerConfiguration::QHttpServerConfiguration()

Default constructs a QHttpServerConfiguration object.

Such a configuration has the following values:

- Rate limit is disabled.
- Maximum connections is disabled.
- Maximum connections per host is disabled.
- Keep-alive timeout is set to 15 seconds.
- Whitelist is empty.
- Blacklist is empty.
- Maximum Url size is 64 KiB.
- Maximum total header size is 64 KiB.
- Maximum header field size is 48 KiB.
- Maximum number of header fields is 128.
- Maximum body size is 32 MiB.

### QHttpServerConfiguration::QHttpServerConfiguration(const QHttpServerConfiguration &other)

Copy-constructs this QHttpServerConfiguration.

### `[constexpr noexcept default]` QHttpServerConfiguration::QHttpServerConfiguration(QHttpServerConfiguration &&other)

Move-constructs this QHttpServerConfiguration from other

### `[noexcept]` QHttpServerConfiguration::~QHttpServerConfiguration()

Destructor.

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

Returns the blacklist of subnets that are denied access by QHttpServer.

This function was introduced in Qt 6.10.

See also setBlacklist().

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

Returns the keep-alive timeout used by QHttpServer. This is the amount of time an idle connections may remain open before it is timed out.

This function was introduced in Qt 6.10.

See also setKeepAliveTimeout().

### `[since 6.11]` qint64 QHttpServerConfiguration::maximumBodySize() const

Returns the maximum size of the incoming body accepted by the server.

This function was introduced in Qt 6.11.

See also setMaximumBodySize().

### `[since 6.12]` quint32 QHttpServerConfiguration::maximumConnections() const

Returns the maximum number of simultaneous connections accepted by the server in total.

Returns 0 if the total connection limit is disabled.

This function was introduced in Qt 6.12.

See also setMaximumConnections().

### `[since 6.12]` quint32 QHttpServerConfiguration::maximumConnectionsPerHost() const

Returns maximum number of simultaneous connections per host that will be accepted by the server. The host is identified by the IP address of the incoming TCP connection.

Returns 0 if the per-host connection limit is disabled.

This function was introduced in Qt 6.12.

See also setMaximumConnectionsPerHost().

### `[since 6.11]` qint64 QHttpServerConfiguration::maximumHeaderFieldCount() const

Returns the maximum number of incoming header fields accepted by the server.

This function was introduced in Qt 6.11.

See also setMaximumHeaderFieldCount().

### `[since 6.11]` qint64 QHttpServerConfiguration::maximumHeaderFieldSize() const

Returns the maximum size of each incoming header field accepted by the server.

This function was introduced in Qt 6.11.

See also setMaximumHeaderFieldSize().

### `[since 6.11]` qint64 QHttpServerConfiguration::maximumTotalHeaderSize() const

Returns the maximum size of the total incoming headers accepted by the server.

This function was introduced in Qt 6.11.

See also setMaximumTotalHeaderSize().

### `[since 6.11]` qint64 QHttpServerConfiguration::maximumUrlSize() const

Returns the maximum size of the URL accepted by the server.

This function was introduced in Qt 6.11.

See also setMaximumUrlSize().

### quint32 QHttpServerConfiguration::rateLimitPerSecond() const

Returns maximum number of incoming requests per second per IP accepted by the server.

This limit is applied separately to each client IP address. Returns 0 if rate limiting is disabled.

See also setRateLimitPerSecond().

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

Sets 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.

By default, the blacklist is empty.

This function was introduced in Qt 6.10.

See also blacklist(), setWhitelist(), and QHostAddress::parseSubnet().

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

Sets 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.

This function was introduced in Qt 6.10.

See also keepAliveTimeout().

### `[since 6.11]` void QHttpServerConfiguration::setMaximumBodySize(qint64 maxSize)

Sets maxSize as the maximum size of the request body that the server will accept. If the limit is exceeded, QHttpServer will respond with status 413 Content Too Large. If maxSize is -1 there is no limit.

The default is 32 MiB.

This function was introduced in Qt 6.11.

See also maximumBodySize() and QHttpServerResponder::StatusCode.

### `[since 6.12]` void QHttpServerConfiguration::setMaximumConnections(quint32 maxConnections)

Sets limit of maxConnections on the total simultaneous connections that will be accepted by the server. If the limit is reached, the server rejects new connections. For HTTP/1 connections, QHttpServer responds with QHttpServerResponder::StatusCode::TooManyRequests and closes the connection.

If maxConnections is set to 0, the total connection limit is disabled.

By default this limit disabled.

This function was introduced in Qt 6.12.

See also maximumConnections() and QHttpServerResponder::StatusCode.

### `[since 6.12]` void QHttpServerConfiguration::setMaximumConnectionsPerHost(quint32 maxConnections)

Sets limit on maxConnections simultaneous connections per host that will will be accepted by QHttpServer. If the limit is exceeded, QHttpServer will respond with QHttpServerResponder::StatusCode::TooManyRequests.

If maxConnections is set to 0, the per-host connection limit is disabled. This should be done when running behind a reverse proxy, as all incoming sockets will appear to originate from the reverse proxy.

When the per-host connection limit is reached, HTTP/1 connections are closed with a 429 (Too Many Requests) response. For SSL connections the connection is closed when the limit is exceeded.

By default this is disabled.

This function was introduced in Qt 6.12.

See also maximumConnectionsPerHost() and QHttpServerResponder::StatusCode.

### `[since 6.11]` void QHttpServerConfiguration::setMaximumHeaderFieldCount(qint64 maxSize)

Sets maxSize as the maximum number of header fields that the server will accept in a request. If the limit is exceeded, QHttpServer will respond with status 431 Request Header Fields Too Large. If maxSize is -1 there is no limit.

The default is 128.

This function was introduced in Qt 6.11.

See also maximumHeaderFieldCount() and QHttpServerResponder::StatusCode.

### `[since 6.11]` void QHttpServerConfiguration::setMaximumHeaderFieldSize(qint64 maxSize)

Sets maxSize as the maximum size of any single header field that the server will accept in a request. If the limit is exceeded, QHttpServer will respond with status 431 Request Header Fields Too Large. If maxSize is -1 there is no limit.

The default is 48 KiB.

This function was introduced in Qt 6.11.

See also maximumHeaderFieldSize() and QHttpServerResponder::StatusCode.

### `[since 6.11]` void QHttpServerConfiguration::setMaximumTotalHeaderSize(qint64 maxSize)

Sets maxSize as the maximum total size of the header fields that the server will accept in a request. If the limit is exceeded, QHttpServer will respond with status 431 Request Header Fields Too Large. If maxSize is -1 there is no limit.

The default is 64 KiB.

This function was introduced in Qt 6.11.

See also maximumTotalHeaderSize() and QHttpServerResponder::StatusCode.

### `[since 6.11]` void QHttpServerConfiguration::setMaximumUrlSize(qint64 maxSize)

Sets maxSize as the maximum size of the request URL that the server will accept. If the limit is exceeded, QHttpServer will respond with status 414 Request-URI Too Long. If maxSize is -1 there is no limit.

The default is 64 KiB.

This function was introduced in Qt 6.11.

See also maximumUrlSize() and QHttpServerResponder::StatusCode.

### void QHttpServerConfiguration::setRateLimitPerSecond(quint32 maxRequests)

Sets 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.

This limit is applied separately to each client IP address. A value of 0 disables rate limiting.

By default, rate limiting is disabled.

See also rateLimitPerSecond() and QHttpServerResponder::StatusCode.

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

Sets 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:

- A base IP address of type QHostAddress.
- A CIDR prefix length of type int, which defines the subnet mask.

To allow only a specific IP address, use a prefix length of 32 for IPv4 (e.g., `"192.168.1.100/32"`) or 128 for IPv6 (e.g., `"2001:db8::1/128"`).

By default, the whitelist is empty.

This function was introduced in Qt 6.10.

See also whitelist(), setBlacklist(), and QHostAddress::parseSubnet().

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

Swaps this configuration with other. This operation is very fast and never fails.

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

Returns the whitelist of subnets allowed by QHttpServer.

When the whitelist is not empty, only addresses in the returned subnets are allowed. The whitelist takes priority over blacklist.

By default, the whitelist is empty.

This function was introduced in Qt 6.10.

See also setWhitelist().

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

Move-assigns other to this QHttpServerConfiguration.

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

Copy-assigns other to this QHttpServerConfiguration.

## Related Non-Members

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

Returns `true` if lhs and rhs do not have the same set of configuration parameters.

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

Returns `true` if lhs and rhs have the same set of configuration parameters.