summaryrefslogtreecommitdiffstats
path: root/src/network/access/qhttpnetworkconnectionchannel.cpp
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2017-02-20 10:34:47 +0100
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2017-03-08 14:14:26 +0000
commit8b9d246225dcd63900399297b0fd553918840bea (patch)
tree9d6e66e3184619a22735d3a8173a81f7ce98159c /src/network/access/qhttpnetworkconnectionchannel.cpp
parent9e7d76946270216d46c8cf0d02427ca3c2109de3 (diff)
QHttpNetworkConnection: fall back gracefully to HTTP/1.1
Both SPDY and HTTP/2 work with a single qhttpnetworkchannel (and this means one socket per qhttpnetworkconnection). Normally, HTTP/1.1 connection is using up to 6 channels/sockets though. At the moment a failure to negotiate SPDY/HTTP/2 leaves us with a downgraded HTTP/1.1 connection (with only one channel vs. default 6). Since we initialize channels (and establish connections) in a 'lazy' manner it's ok to pre-allocate all 6 channels and then either use 1 (if SPDY/HTTP/2 indeed was negotiated) or switch back to 6 in case of failure. Change-Id: Ia6c3061463c4d634aaed05ce0dde47bfb5e24dd8 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/network/access/qhttpnetworkconnectionchannel.cpp')
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
index 7fa19dc65b..a11fc7e807 100644
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
@@ -1082,12 +1082,36 @@ void QHttpNetworkConnectionChannel::_q_encrypted()
}
}
Q_FALLTHROUGH();
- case QSslConfiguration::NextProtocolNegotiationNone:
+ case QSslConfiguration::NextProtocolNegotiationNone: {
protocolHandler.reset(new QHttpProtocolHandler(this));
+
+ QList<QByteArray> protocols = sslConfiguration.allowedNextProtocols();
+ const int nProtocols = protocols.size();
+ // Clear the protocol that we failed to negotiate, so we do not try
+ // it again on other channels that our connection can create/open.
+ if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2)
+ protocols.removeAll(QSslConfiguration::ALPNProtocolHTTP2);
+ else if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY)
+ protocols.removeAll(QSslConfiguration::NextProtocolSpdy3_0);
+
+ if (nProtocols > protocols.size()) {
+ sslConfiguration.setAllowedNextProtocols(protocols);
+ const int channelCount = connection->d_func()->channelCount;
+ for (int i = 0; i < channelCount; ++i)
+ connection->d_func()->channels[i].setSslConfiguration(sslConfiguration);
+ }
+
connection->setConnectionType(QHttpNetworkConnection::ConnectionTypeHTTP);
- // re-queue requests from SPDY queue to HTTP queue, if any
- requeueSpdyRequests();
+ // We use only one channel for SPDY or HTTP/2, but normally six for
+ // HTTP/1.1 - let's restore this number to the reserved number of
+ // channels:
+ if (connection->d_func()->activeChannelCount < connection->d_func()->channelCount) {
+ connection->d_func()->activeChannelCount = connection->d_func()->channelCount;
+ // re-queue requests from SPDY queue to HTTP queue, if any
+ requeueSpdyRequests();
+ }
break;
+ }
default:
emitFinishedWithError(QNetworkReply::SslHandshakeFailedError,
"detected unknown Next Protocol Negotiation protocol");