QHstsPolicy Class

The QHstsPolicy class specifies that a host supports HTTP Strict Transport Security policy (HSTS). More...

Header: #include <QHstsPolicy>
qmake: QT += network
Since: Qt 5.9

This class was introduced in Qt 5.9.

Public Types

enum PolicyFlag { IncludeSubDomains }
flags PolicyFlags

Public Functions

QHstsPolicy(const QHstsPolicy &other)
QHstsPolicy(const QDateTime &expiry, QHstsPolicy::PolicyFlags flags, const QString &host, QUrl::ParsingMode mode = QUrl::DecodedMode)
QHstsPolicy &operator=(const QHstsPolicy &other)
QDateTime expiry() const
QString host(QUrl::ComponentFormattingOptions options = QUrl::FullyDecoded) const
bool includesSubDomains() const
bool isExpired() const
void setExpiry(const QDateTime &expiry)
void setHost(const QString &host, QUrl::ParsingMode mode = QUrl::DecodedMode)
void setIncludesSubDomains(bool include)
void swap(QHstsPolicy &other)

Detailed Description

HSTS policy defines a period of time during which QNetworkAccessManager should only access a host in a secure fashion. HSTS policy is defined by RFC6797.

You can set expiry time and host name for this policy, and control whether it applies to subdomains, either in the constructor or by calling setExpiry(), setHost() and setIncludesSubdomains().

See also QNetworkAccessManager::setStrictTransportSecurityEnabled().

Member Type Documentation

enum QHstsPolicy::PolicyFlag
flags QHstsPolicy::PolicyFlags

QHstsPolicy::IncludeSubDomains1Indicates whether a policy must include subdomains

The PolicyFlags type is a typedef for QFlags<PolicyFlag>. It stores an OR combination of PolicyFlag values.

Member Function Documentation

QHstsPolicy::QHstsPolicy(const QHstsPolicy &other)

Creates a copy of other object.

QHstsPolicy::QHstsPolicy(const QDateTime &expiry, QHstsPolicy::PolicyFlags flags, const QString &host, QUrl::ParsingMode mode = QUrl::DecodedMode)

Constructs QHstsPolicy with expiry (in UTC); flags is a value indicating whether this policy must also include subdomains, host data is interpreted according to mode.

See also QUrl::setHost(), QUrl::ParsingMode, and QHstsPolicy::PolicyFlag.


Constructs an invalid (expired) policy with empty host name and subdomains not included.

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

Copy-assignment operator, makes a copy of other.



QDateTime QHstsPolicy::expiry() const

Returns the expiration date for the policy (in UTC).

See also setExpiry().

QString QHstsPolicy::host(QUrl::ComponentFormattingOptions options = QUrl::FullyDecoded) const

Returns a host for a given policy, formatted according to options.

See also setHost(), QUrl::host(), and QUrl::ComponentFormattingOptions.

bool QHstsPolicy::includesSubDomains() const

Returns true if this policy also includes subdomains.

See also setIncludesSubDomains().

bool QHstsPolicy::isExpired() const

Return true if this policy has a valid expiration date and this date is greater than QDateTime::currentGetDateTimeUtc().

See also setExpiry() and expiry().

void QHstsPolicy::setExpiry(const QDateTime &expiry)

Sets the expiration date for the policy (in UTC) to expiry.

See also expiry().

void QHstsPolicy::setHost(const QString &host, QUrl::ParsingMode mode = QUrl::DecodedMode)

Sets a host, host data is interpreted according to mode parameter.

See also host(), QUrl::setHost(), and QUrl::ParsingMode.

void QHstsPolicy::setIncludesSubDomains(bool include)

Sets whether subdomains are included for this policy to include.

See also includesSubDomains().

void QHstsPolicy::swap(QHstsPolicy &other)

Swaps this policy with the other policy.

© 2024 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.