diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2020-08-06 12:52:17 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2020-09-10 18:28:43 +0200 |
commit | 8a3847aab94577981593b9dd900fbd306b202ab6 (patch) | |
tree | 03bfe9a3b9e60d3c3b589cc1bca74961e7640bdd /src | |
parent | 00d9a0ea8e0796a4ebf19ea15550d66adcf1af86 (diff) | |
download | qtbase-8a3847aab94577981593b9dd900fbd306b202ab6.tar.gz |
QNAM: Enable HTTP/2 by default
It has been in Qt for some years now and 6.0 marks a good point to
enable it by default. The exception is connectToHostEncrypted where we
still require the users to enable it explicitly since there's no logical
way to disable it.
[ChangeLog][QtNetwork][QNetworkAccessManager] HTTP/2 is now enabled by
default.
Fixes: QTBUG-85902
Change-Id: Ia029a045727cc593d77df9eb3a5888522ad19199
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/network/access/qhttpnetworkrequest.cpp | 2 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessmanager.cpp | 20 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 6 | ||||
-rw-r--r-- | src/network/access/qnetworkrequest.cpp | 2 |
4 files changed, 16 insertions, 14 deletions
diff --git a/src/network/access/qhttpnetworkrequest.cpp b/src/network/access/qhttpnetworkrequest.cpp index 185435a1f1..7ef033047e 100644 --- a/src/network/access/qhttpnetworkrequest.cpp +++ b/src/network/access/qhttpnetworkrequest.cpp @@ -45,7 +45,7 @@ QT_BEGIN_NAMESPACE QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op, QHttpNetworkRequest::Priority pri, const QUrl &newUrl) : QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), uploadByteDevice(nullptr), - autoDecompress(false), pipeliningAllowed(false), http2Allowed(false), + autoDecompress(false), pipeliningAllowed(false), http2Allowed(true), http2Direct(false), withCredentials(true), preConnect(false), redirectCount(0), redirectPolicy(QNetworkRequest::ManualRedirectPolicy) { diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 4642700887..b82864c52e 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -931,9 +931,9 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ \a sslConfiguration. This function is useful to complete the TCP and SSL handshake to a host before the HTTPS request is made, resulting in a lower network latency. - \note Preconnecting a SPDY connection can be done by calling setAllowedNextProtocols() - on \a sslConfiguration with QSslConfiguration::NextProtocolSpdy3_0 contained in - the list of allowed protocols. When using SPDY, one single connection per host is + \note Preconnecting a HTTP/2 connection can be done by calling setAllowedNextProtocols() + on \a sslConfiguration with QSslConfiguration::ALPNProtocolHTTP2 contained in + the list of allowed protocols. When using HTTP/2, one single connection per host is enough, i.e. calling this method multiple times per host will not result in faster network transactions. @@ -957,9 +957,9 @@ void QNetworkAccessManager::connectToHostEncrypted(const QString &hostName, quin validation. This function is useful to complete the TCP and SSL handshake to a host before the HTTPS request is made, resulting in a lower network latency. - \note Preconnecting a SPDY connection can be done by calling setAllowedNextProtocols() - on \a sslConfiguration with QSslConfiguration::NextProtocolSpdy3_0 contained in - the list of allowed protocols. When using SPDY, one single connection per host is + \note Preconnecting a HTTP/2 connection can be done by calling setAllowedNextProtocols() + on \a sslConfiguration with QSslConfiguration::ALPNProtocolHTTP2 contained in + the list of allowed protocols. When using HTTP/2, one single connection per host is enough, i.e. calling this method multiple times per host will not result in faster network transactions. @@ -980,10 +980,10 @@ void QNetworkAccessManager::connectToHostEncrypted(const QString &hostName, quin if (sslConfiguration != QSslConfiguration::defaultConfiguration()) request.setSslConfiguration(sslConfiguration); - // There is no way to enable HTTP2 via a request, so we need to check - // the ssl configuration whether HTTP2 is allowed here. - if (sslConfiguration.allowedNextProtocols().contains(QSslConfiguration::ALPNProtocolHTTP2)) - request.setAttribute(QNetworkRequest::Http2AllowedAttribute, true); + // There is no way to enable HTTP2 via a request after having established the connection, + // so we need to check the ssl configuration whether HTTP2 is allowed here. + if (!sslConfiguration.allowedNextProtocols().contains(QSslConfiguration::ALPNProtocolHTTP2)) + request.setAttribute(QNetworkRequest::Http2AllowedAttribute, false); request.setPeerVerifyName(peerName); get(request); diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index bdb81ee0b1..5ba11333bf 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -755,8 +755,10 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq if (newHttpRequest.attribute(QNetworkRequest::HttpPipeliningAllowedAttribute).toBool()) httpRequest.setPipeliningAllowed(true); - if (request.attribute(QNetworkRequest::Http2AllowedAttribute).toBool()) - httpRequest.setHTTP2Allowed(true); + if (auto allowed = request.attribute(QNetworkRequest::Http2AllowedAttribute); + allowed.isValid() && allowed.canConvert<bool>()) { + httpRequest.setHTTP2Allowed(allowed.value<bool>()); + } if (request.attribute(QNetworkRequest::Http2DirectAttribute).toBool()) { // Intentionally mutually exclusive - cannot be both direct and 'allowed' diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 03a7f0b176..a1e17834c0 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -269,7 +269,7 @@ QT_BEGIN_NAMESPACE to different policies. \value Http2AllowedAttribute - Requests only, type: QMetaType::Bool (default: false) + Requests only, type: QMetaType::Bool (default: true) Indicates whether the QNetworkAccessManager code is allowed to use HTTP/2 with this request. This applies to SSL requests or 'cleartext' HTTP/2. |