QNAM: Disable h2c by default

And since it's relatively unlikely to be used, just leave it
behind a environment variable for now.

[ChangeLog][QtNetwork][Potentially Source-Incompatible] Support for
clear-text http/2 was disabled due to incompatibility with certain
servers. If you were relying on this feature you must re-enable it by
setting the QT_NETWORK_ALLOW_H2C environment variable. For a later
version of Qt it will get a dedicated attribute.

Pick-to: 6.2
Task-number: QTBUG-98642
Change-Id: Id3e360726e285b3128e3e3f4bce9440404c9ad6e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
bb10
Mårten Nordheim 2021-11-26 13:15:46 +01:00
parent ca9d72f465
commit 4c930e9d13
4 changed files with 20 additions and 0 deletions

View File

@ -365,6 +365,16 @@ void QHttpNetworkRequest::setHTTP2Direct(bool b)
d->http2Direct = b;
}
bool QHttpNetworkRequest::isH2cAllowed() const
{
return qEnvironmentVariableIsSet("QT_NETWORK_H2C_ALLOWED");
}
void QHttpNetworkRequest::setH2cAllowed(bool b)
{
Q_UNUSED(b);
}
bool QHttpNetworkRequest::withCredentials() const
{
return d->withCredentials;

View File

@ -125,6 +125,9 @@ public:
bool isHTTP2Direct() const;
void setHTTP2Direct(bool b);
bool isH2cAllowed() const;
void setH2cAllowed(bool b);
bool withCredentials() const;
void setWithCredentials(bool b);

View File

@ -290,6 +290,12 @@ void QHttpThreadDelegate::startRequest()
connectionType = QHttpNetworkConnection::ConnectionTypeHTTP2Direct;
}
// Use HTTP/1.1 if h2c is not allowed and we would otherwise choose to use it
if (!ssl && connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2
&& !httpRequest.isH2cAllowed()) {
connectionType = QHttpNetworkConnection::ConnectionTypeHTTP;
}
#if QT_CONFIG(ssl)
// See qnetworkreplyhttpimpl, delegate's initialization code.
Q_ASSERT(!ssl || incomingSslConfiguration.data());

View File

@ -223,6 +223,7 @@ tst_Http2::~tst_Http2()
void tst_Http2::init()
{
manager.reset(new QNetworkAccessManager);
qputenv("QT_NETWORK_H2C_ALLOWED", "1");
}
void tst_Http2::singleRequest_data()