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>
This commit is contained in:
parent
00d9a0ea8e
commit
8a3847aab9
@ -45,7 +45,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op,
|
QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op,
|
||||||
QHttpNetworkRequest::Priority pri, const QUrl &newUrl)
|
QHttpNetworkRequest::Priority pri, const QUrl &newUrl)
|
||||||
: QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), uploadByteDevice(nullptr),
|
: 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),
|
http2Direct(false), withCredentials(true), preConnect(false), redirectCount(0),
|
||||||
redirectPolicy(QNetworkRequest::ManualRedirectPolicy)
|
redirectPolicy(QNetworkRequest::ManualRedirectPolicy)
|
||||||
{
|
{
|
||||||
|
@ -931,9 +931,9 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ
|
|||||||
\a sslConfiguration. This function is useful to complete the TCP and SSL handshake
|
\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.
|
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()
|
\note Preconnecting a HTTP/2 connection can be done by calling setAllowedNextProtocols()
|
||||||
on \a sslConfiguration with QSslConfiguration::NextProtocolSpdy3_0 contained in
|
on \a sslConfiguration with QSslConfiguration::ALPNProtocolHTTP2 contained in
|
||||||
the list of allowed protocols. When using SPDY, one single connection per host is
|
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
|
enough, i.e. calling this method multiple times per host will not result in faster
|
||||||
network transactions.
|
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
|
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.
|
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()
|
\note Preconnecting a HTTP/2 connection can be done by calling setAllowedNextProtocols()
|
||||||
on \a sslConfiguration with QSslConfiguration::NextProtocolSpdy3_0 contained in
|
on \a sslConfiguration with QSslConfiguration::ALPNProtocolHTTP2 contained in
|
||||||
the list of allowed protocols. When using SPDY, one single connection per host is
|
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
|
enough, i.e. calling this method multiple times per host will not result in faster
|
||||||
network transactions.
|
network transactions.
|
||||||
|
|
||||||
@ -980,10 +980,10 @@ void QNetworkAccessManager::connectToHostEncrypted(const QString &hostName, quin
|
|||||||
if (sslConfiguration != QSslConfiguration::defaultConfiguration())
|
if (sslConfiguration != QSslConfiguration::defaultConfiguration())
|
||||||
request.setSslConfiguration(sslConfiguration);
|
request.setSslConfiguration(sslConfiguration);
|
||||||
|
|
||||||
// There is no way to enable HTTP2 via a request, so we need to check
|
// There is no way to enable HTTP2 via a request after having established the connection,
|
||||||
// the ssl configuration whether HTTP2 is allowed here.
|
// so we need to check the ssl configuration whether HTTP2 is allowed here.
|
||||||
if (sslConfiguration.allowedNextProtocols().contains(QSslConfiguration::ALPNProtocolHTTP2))
|
if (!sslConfiguration.allowedNextProtocols().contains(QSslConfiguration::ALPNProtocolHTTP2))
|
||||||
request.setAttribute(QNetworkRequest::Http2AllowedAttribute, true);
|
request.setAttribute(QNetworkRequest::Http2AllowedAttribute, false);
|
||||||
|
|
||||||
request.setPeerVerifyName(peerName);
|
request.setPeerVerifyName(peerName);
|
||||||
get(request);
|
get(request);
|
||||||
|
@ -755,8 +755,10 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq
|
|||||||
if (newHttpRequest.attribute(QNetworkRequest::HttpPipeliningAllowedAttribute).toBool())
|
if (newHttpRequest.attribute(QNetworkRequest::HttpPipeliningAllowedAttribute).toBool())
|
||||||
httpRequest.setPipeliningAllowed(true);
|
httpRequest.setPipeliningAllowed(true);
|
||||||
|
|
||||||
if (request.attribute(QNetworkRequest::Http2AllowedAttribute).toBool())
|
if (auto allowed = request.attribute(QNetworkRequest::Http2AllowedAttribute);
|
||||||
httpRequest.setHTTP2Allowed(true);
|
allowed.isValid() && allowed.canConvert<bool>()) {
|
||||||
|
httpRequest.setHTTP2Allowed(allowed.value<bool>());
|
||||||
|
}
|
||||||
|
|
||||||
if (request.attribute(QNetworkRequest::Http2DirectAttribute).toBool()) {
|
if (request.attribute(QNetworkRequest::Http2DirectAttribute).toBool()) {
|
||||||
// Intentionally mutually exclusive - cannot be both direct and 'allowed'
|
// Intentionally mutually exclusive - cannot be both direct and 'allowed'
|
||||||
|
@ -269,7 +269,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
to different policies.
|
to different policies.
|
||||||
|
|
||||||
\value Http2AllowedAttribute
|
\value Http2AllowedAttribute
|
||||||
Requests only, type: QMetaType::Bool (default: false)
|
Requests only, type: QMetaType::Bool (default: true)
|
||||||
Indicates whether the QNetworkAccessManager code is
|
Indicates whether the QNetworkAccessManager code is
|
||||||
allowed to use HTTP/2 with this request. This applies
|
allowed to use HTTP/2 with this request. This applies
|
||||||
to SSL requests or 'cleartext' HTTP/2.
|
to SSL requests or 'cleartext' HTTP/2.
|
||||||
|
@ -386,7 +386,6 @@ void tst_qnetworkreply::npnWithEmptyList() // QTBUG-40714
|
|||||||
|
|
||||||
QUrl url(QStringLiteral("https://www.ossifrage.net/"));
|
QUrl url(QStringLiteral("https://www.ossifrage.net/"));
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
request.setAttribute(QNetworkRequest::Http2AllowedAttribute, QVariant(true));
|
|
||||||
QNetworkReply *reply = m_manager.get(request);
|
QNetworkReply *reply = m_manager.get(request);
|
||||||
QObject::connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
QObject::connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user