diff options
Diffstat (limited to 'src/network/access/qhttpnetworkconnection.cpp')
-rw-r--r-- | src/network/access/qhttpnetworkconnection.cpp | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index d82fb46356..73bf8bebc3 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -570,9 +570,15 @@ void QHttpNetworkConnectionPrivate::createAuthorization(QAbstractSocket *socket, QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(*authenticator); // Send "Authorization" header, but not if it's NTLM and the socket is already authenticated. if (priv && priv->method != QAuthenticatorPrivate::None) { - if ((priv->method != QAuthenticatorPrivate::Ntlm - && request.headerField("Authorization").isEmpty()) - || channel.lastStatus == 401) { + const bool ntlmNego = priv->method == QAuthenticatorPrivate::Ntlm + || priv->method == QAuthenticatorPrivate::Negotiate; + const bool authNeeded = channel.lastStatus == 401; + const bool ntlmNegoOk = ntlmNego && authNeeded + && (priv->phase != QAuthenticatorPrivate::Done + || !channel.authenticationCredentialsSent); + const bool otherOk = + !ntlmNego && (authNeeded || request.headerField("Authorization").isEmpty()); + if (ntlmNegoOk || otherOk) { QByteArray response = priv->calculateResponse(request.methodName(), request.uri(false), request.url().host()); request.setHeaderField("Authorization", response); @@ -585,7 +591,13 @@ void QHttpNetworkConnectionPrivate::createAuthorization(QAbstractSocket *socket, priv = QAuthenticatorPrivate::getPrivate(*authenticator); // Send "Proxy-Authorization" header, but not if it's NTLM and the socket is already authenticated. if (priv && priv->method != QAuthenticatorPrivate::None) { - if (priv->method != QAuthenticatorPrivate::Ntlm || channel.lastStatus == 407) { + const bool ntlmNego = priv->method == QAuthenticatorPrivate::Ntlm + || priv->method == QAuthenticatorPrivate::Negotiate; + const bool proxyAuthNeeded = channel.lastStatus == 407; + const bool ntlmNegoOk = ntlmNego && proxyAuthNeeded + && (priv->phase != QAuthenticatorPrivate::Done || !channel.proxyCredentialsSent); + const bool otherOk = !ntlmNego; + if (ntlmNegoOk || otherOk) { QByteArray response = priv->calculateResponse(request.methodName(), request.uri(false), networkProxy.hostName()); request.setHeaderField("Proxy-Authorization", response); @@ -750,7 +762,7 @@ void QHttpNetworkConnectionPrivate::fillPipeline(QAbstractSocket *socket) if (channels[i].reply == nullptr) return; - if (! (defaultPipelineLength - channels[i].alreadyPipelinedRequests.length() >= defaultRePipelineLength)) { + if (! (defaultPipelineLength - channels[i].alreadyPipelinedRequests.size() >= defaultRePipelineLength)) { return; } @@ -791,28 +803,28 @@ void QHttpNetworkConnectionPrivate::fillPipeline(QAbstractSocket *socket) int lengthBefore; while (!highPriorityQueue.isEmpty()) { - lengthBefore = channels[i].alreadyPipelinedRequests.length(); + lengthBefore = channels[i].alreadyPipelinedRequests.size(); fillPipeline(highPriorityQueue, channels[i]); - if (channels[i].alreadyPipelinedRequests.length() >= defaultPipelineLength) { + if (channels[i].alreadyPipelinedRequests.size() >= defaultPipelineLength) { channels[i].pipelineFlush(); return; } - if (lengthBefore == channels[i].alreadyPipelinedRequests.length()) + if (lengthBefore == channels[i].alreadyPipelinedRequests.size()) break; // did not process anything, now do the low prio queue } while (!lowPriorityQueue.isEmpty()) { - lengthBefore = channels[i].alreadyPipelinedRequests.length(); + lengthBefore = channels[i].alreadyPipelinedRequests.size(); fillPipeline(lowPriorityQueue, channels[i]); - if (channels[i].alreadyPipelinedRequests.length() >= defaultPipelineLength) { + if (channels[i].alreadyPipelinedRequests.size() >= defaultPipelineLength) { channels[i].pipelineFlush(); return; } - if (lengthBefore == channels[i].alreadyPipelinedRequests.length()) + if (lengthBefore == channels[i].alreadyPipelinedRequests.size()) break; // did not process anything } @@ -826,7 +838,7 @@ bool QHttpNetworkConnectionPrivate::fillPipeline(QList<HttpMessagePair> &queue, if (queue.isEmpty()) return true; - for (int i = queue.count() - 1; i >= 0; --i) { + for (int i = queue.size() - 1; i >= 0; --i) { HttpMessagePair messagePair = queue.at(i); const QHttpNetworkRequest &request = messagePair.first; @@ -948,7 +960,7 @@ void QHttpNetworkConnectionPrivate::removeReply(QHttpNetworkReply *reply) } // is the reply inside the pipeline of this channel already? - for (int j = 0; j < channels[i].alreadyPipelinedRequests.length(); j++) { + for (int j = 0; j < channels[i].alreadyPipelinedRequests.size(); j++) { if (channels[i].alreadyPipelinedRequests.at(j).second == reply) { // Remove that HttpMessagePair channels[i].alreadyPipelinedRequests.removeAt(j); @@ -982,7 +994,7 @@ void QHttpNetworkConnectionPrivate::removeReply(QHttpNetworkReply *reply) } // remove from the high priority queue if (!highPriorityQueue.isEmpty()) { - for (int j = highPriorityQueue.count() - 1; j >= 0; --j) { + for (int j = highPriorityQueue.size() - 1; j >= 0; --j) { HttpMessagePair messagePair = highPriorityQueue.at(j); if (messagePair.second == reply) { highPriorityQueue.removeAt(j); @@ -993,7 +1005,7 @@ void QHttpNetworkConnectionPrivate::removeReply(QHttpNetworkReply *reply) } // remove from the low priority queue if (!lowPriorityQueue.isEmpty()) { - for (int j = lowPriorityQueue.count() - 1; j >= 0; --j) { + for (int j = lowPriorityQueue.size() - 1; j >= 0; --j) { HttpMessagePair messagePair = lowPriorityQueue.at(j); if (messagePair.second == reply) { lowPriorityQueue.removeAt(j); @@ -1096,7 +1108,7 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest() // If there is not already any connected channels we need to connect a new one. // We do not pair the channel with the request until we know if it is // connected or not. This is to reuse connected channels before we connect new once. - int queuedRequests = highPriorityQueue.count() + lowPriorityQueue.count(); + int queuedRequests = highPriorityQueue.size() + lowPriorityQueue.size(); // in case we have in-flight preconnect requests and normal requests, // we only need one socket for each (preconnect, normal request) pair @@ -1249,7 +1261,7 @@ void QHttpNetworkConnectionPrivate::_q_hostLookupFinished(const QHostInfo &info) networkLayerState = QHttpNetworkConnectionPrivate::Unknown; } else if (connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2 || connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2Direct) { - for (const HttpMessagePair &h2Pair : qAsConst(channels[0].h2RequestsToSend)) { + for (const HttpMessagePair &h2Pair : std::as_const(channels[0].h2RequestsToSend)) { // emit error for all replies QHttpNetworkReply *currentReply = h2Pair.second; Q_ASSERT(currentReply); @@ -1546,12 +1558,12 @@ void QHttpNetworkConnectionPrivate::emitProxyAuthenticationRequired(const QHttpN pauseConnection(); QHttpNetworkReply *reply; if ((connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2 - && (chan->switchedToHttp2 || chan->h2RequestsToSend.count() > 0)) + && (chan->switchedToHttp2 || chan->h2RequestsToSend.size() > 0)) || connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2Direct) { // we choose the reply to emit the proxyAuth signal from somewhat arbitrarily, // but that does not matter because the signal will ultimately be emitted // by the QNetworkAccessManager. - Q_ASSERT(chan->h2RequestsToSend.count() > 0); + Q_ASSERT(chan->h2RequestsToSend.size() > 0); reply = chan->h2RequestsToSend.cbegin().value().second; } else { // HTTP reply = chan->reply; |