QHstsPolicy: Replace bool with QFlags
As pointed out in the previous code-review: Replace a bool ctor parameter with QFlags<enum> to conform to Qt API Design Principles (Boolean Parameter Trap). Since the bool with its many unwanted implicit conversions is gone from the ctor parameter list now, drop the explicit keyword again. It was requested because of the boolean parameter in the first place. Change-Id: Ibaf287a6a3e38c22f033fd5d9e024c54f30a1fd4 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
8afc6146be
commit
075e669cbe
@ -110,7 +110,11 @@ void QHstsCache::updateKnownHost(const QString &host, const QDateTime &expires,
|
||||
// IDNA 2003 (RFC3490) for us, as required by HSTS (RFC6797, section 10).
|
||||
const HostName hostName(host);
|
||||
const auto pos = knownHosts.find(hostName);
|
||||
const QHstsPolicy newPolicy(expires, includeSubDomains, hostName.name);
|
||||
QHstsPolicy::PolicyFlags flags;
|
||||
if (includeSubDomains)
|
||||
flags = QHstsPolicy::IncludeSubDomains;
|
||||
|
||||
const QHstsPolicy newPolicy(expires, flags, hostName.name);
|
||||
if (pos == knownHosts.end()) {
|
||||
// A new, previously unknown host.
|
||||
if (newPolicy.isExpired()) {
|
||||
|
@ -63,6 +63,14 @@ QT_BEGIN_NAMESPACE
|
||||
\sa QNetworkAccessManager::setStrictTransportSecurityEnabled()
|
||||
*/
|
||||
|
||||
/*
|
||||
\enum QHstsPolicy::PolicyFlag
|
||||
|
||||
Specifies attributes that a policy can have.
|
||||
|
||||
\value IncludeSubDomains HSTS policy also applies to subdomains.
|
||||
*/
|
||||
|
||||
class QHstsPolicyPrivate : public QSharedData
|
||||
{
|
||||
public:
|
||||
@ -101,13 +109,13 @@ QHstsPolicy::QHstsPolicy() : d(new QHstsPolicyPrivate)
|
||||
|
||||
\sa QUrl::setHost(), QUrl::ParsingMode
|
||||
*/
|
||||
QHstsPolicy::QHstsPolicy(const QDateTime &expiry, bool includeSubDomains, const QString &host,
|
||||
QUrl::ParsingMode mode)
|
||||
QHstsPolicy::QHstsPolicy(const QDateTime &expiry, PolicyFlags flags,
|
||||
const QString &host, QUrl::ParsingMode mode)
|
||||
: d(new QHstsPolicyPrivate)
|
||||
{
|
||||
d->url.setHost(host, mode);
|
||||
d->expiry = expiry;
|
||||
d->includeSubDomains = includeSubDomains;
|
||||
d->includeSubDomains = flags.testFlag(IncludeSubDomains);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <QtNetwork/qtnetworkglobal.h>
|
||||
|
||||
#include <QtCore/qshareddata.h>
|
||||
#include <QtCore/qflags.h>
|
||||
#include <QtCore/qurl.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -53,10 +54,15 @@ class QString;
|
||||
class Q_NETWORK_EXPORT QHstsPolicy
|
||||
{
|
||||
public:
|
||||
enum PolicyFlag
|
||||
{
|
||||
IncludeSubDomains = 1
|
||||
};
|
||||
Q_DECLARE_FLAGS(PolicyFlags, PolicyFlag)
|
||||
|
||||
QHstsPolicy();
|
||||
explicit QHstsPolicy(const QDateTime &expiry, bool includeSubDomains, const QString &host,
|
||||
QUrl::ParsingMode mode = QUrl::DecodedMode);
|
||||
QHstsPolicy(const QDateTime &expiry, PolicyFlags flags, const QString &host,
|
||||
QUrl::ParsingMode mode = QUrl::DecodedMode);
|
||||
QHstsPolicy(const QHstsPolicy &rhs);
|
||||
QHstsPolicy &operator=(const QHstsPolicy &rhs);
|
||||
QHstsPolicy &operator=(QHstsPolicy &&other) Q_DECL_NOTHROW { swap(other); return *this; }
|
||||
@ -81,6 +87,7 @@ private:
|
||||
};
|
||||
|
||||
Q_DECLARE_SHARED(QHstsPolicy)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QHstsPolicy::PolicyFlags)
|
||||
|
||||
Q_NETWORK_EXPORT bool operator==(const QHstsPolicy &lhs, const QHstsPolicy &rhs);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user