| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qhttpnetworkconnectionchannel.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Copyright (C) 2014 BlackBerry Limited. All rights reserved. | - | ||||||||||||||||||
| 5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 6 | ** | - | ||||||||||||||||||
| 7 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||||||||
| 8 | ** | - | ||||||||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 17 | ** | - | ||||||||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 22 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 36 | ** | - | ||||||||||||||||||
| 37 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 38 | ** | - | ||||||||||||||||||
| 39 | ****************************************************************************/ | - | ||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | #include "qhttpnetworkconnectionchannel_p.h" | - | ||||||||||||||||||
| 42 | #include "qhttpnetworkconnection_p.h" | - | ||||||||||||||||||
| 43 | #include "private/qnoncontiguousbytedevice_p.h" | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | #include <qpair.h> | - | ||||||||||||||||||
| 46 | #include <qdebug.h> | - | ||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | #ifndef QT_NO_HTTP | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | #include <private/qhttpprotocolhandler_p.h> | - | ||||||||||||||||||
| 51 | #include <private/qspdyprotocolhandler_p.h> | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 54 | # include <QtNetwork/qsslkey.h> | - | ||||||||||||||||||
| 55 | # include <QtNetwork/qsslcipher.h> | - | ||||||||||||||||||
| 56 | # include <QtNetwork/qsslconfiguration.h> | - | ||||||||||||||||||
| 57 | #endif | - | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 60 | #include "private/qnetworksession_p.h" | - | ||||||||||||||||||
| 61 | #endif | - | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | // TODO: Put channel specific stuff here so it does not polute qhttpnetworkconnection.cpp | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | // Because in-flight when sending a request, the server might close our connection (because the persistent HTTP | - | ||||||||||||||||||
| 68 | // connection times out) | - | ||||||||||||||||||
| 69 | // We use 3 because we can get a _q_error 3 times depending on the timing: | - | ||||||||||||||||||
| 70 | static const int reconnectAttemptsDefault = 3; | - | ||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel() | - | ||||||||||||||||||
| 73 | : socket(0) | - | ||||||||||||||||||
| 74 | , ssl(false) | - | ||||||||||||||||||
| 75 | , isInitialized(false) | - | ||||||||||||||||||
| 76 | , state(IdleState) | - | ||||||||||||||||||
| 77 | , reply(0) | - | ||||||||||||||||||
| 78 | , written(0) | - | ||||||||||||||||||
| 79 | , bytesTotal(0) | - | ||||||||||||||||||
| 80 | , resendCurrent(false) | - | ||||||||||||||||||
| 81 | , lastStatus(0) | - | ||||||||||||||||||
| 82 | , pendingEncrypt(false) | - | ||||||||||||||||||
| 83 | , reconnectAttempts(reconnectAttemptsDefault) | - | ||||||||||||||||||
| 84 | , authMethod(QAuthenticatorPrivate::None) | - | ||||||||||||||||||
| 85 | , proxyAuthMethod(QAuthenticatorPrivate::None) | - | ||||||||||||||||||
| 86 | , authenticationCredentialsSent(false) | - | ||||||||||||||||||
| 87 | , proxyCredentialsSent(false) | - | ||||||||||||||||||
| 88 | , protocolHandler(0) | - | ||||||||||||||||||
| 89 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 90 | , ignoreAllSslErrors(false) | - | ||||||||||||||||||
| 91 | #endif | - | ||||||||||||||||||
| 92 | , pipeliningSupported(PipeliningSupportUnknown) | - | ||||||||||||||||||
| 93 | , networkLayerPreference(QAbstractSocket::AnyIPProtocol) | - | ||||||||||||||||||
| 94 | , connection(0) | - | ||||||||||||||||||
| 95 | { | - | ||||||||||||||||||
| 96 | // Inlining this function in the header leads to compiler error on | - | ||||||||||||||||||
| 97 | // release-armv5, on at least timebox 9.2 and 10.1. | - | ||||||||||||||||||
| 98 | } executed 3416 times by 8 tests: end of blockExecuted by:
| 3416 | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | void QHttpNetworkConnectionChannel::init() | - | ||||||||||||||||||
| 101 | { | - | ||||||||||||||||||
| 102 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 103 | if (connection->d_func()->encrypt)
| 108-646 | ||||||||||||||||||
| 104 | socket = new QSslSocket; executed 108 times by 3 tests: socket = new QSslSocket;Executed by:
| 108 | ||||||||||||||||||
| 105 | else | - | ||||||||||||||||||
| 106 | socket = new QTcpSocket; executed 646 times by 8 tests: socket = new QTcpSocket;Executed by:
| 646 | ||||||||||||||||||
| 107 | #else | - | ||||||||||||||||||
| 108 | socket = new QTcpSocket; | - | ||||||||||||||||||
| 109 | #endif | - | ||||||||||||||||||
| 110 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 111 | //push session down to socket | - | ||||||||||||||||||
| 112 | if (networkSession)
| 44-710 | ||||||||||||||||||
| 113 | socket->setProperty("_q_networksession", QVariant::fromValue(networkSession)); executed 710 times by 8 tests: socket->setProperty("_q_networksession", QVariant::fromValue(networkSession));Executed by:
| 710 | ||||||||||||||||||
| 114 | #endif | - | ||||||||||||||||||
| 115 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 116 | // Set by QNAM anyway, but let's be safe here | - | ||||||||||||||||||
| 117 | socket->setProxy(QNetworkProxy::NoProxy); | - | ||||||||||||||||||
| 118 | #endif | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | // After some back and forth in all the last years, this is now a DirectConnection because otherwise | - | ||||||||||||||||||
| 121 | // the state inside the *Socket classes gets messed up, also in conjunction with the socket notifiers | - | ||||||||||||||||||
| 122 | // which behave slightly differently on Windows vs Linux | - | ||||||||||||||||||
| 123 | QObject::connect(socket, SIGNAL(bytesWritten(qint64)), | - | ||||||||||||||||||
| 124 | this, SLOT(_q_bytesWritten(qint64)), | - | ||||||||||||||||||
| 125 | Qt::DirectConnection); | - | ||||||||||||||||||
| 126 | QObject::connect(socket, SIGNAL(connected()), | - | ||||||||||||||||||
| 127 | this, SLOT(_q_connected()), | - | ||||||||||||||||||
| 128 | Qt::DirectConnection); | - | ||||||||||||||||||
| 129 | QObject::connect(socket, SIGNAL(readyRead()), | - | ||||||||||||||||||
| 130 | this, SLOT(_q_readyRead()), | - | ||||||||||||||||||
| 131 | Qt::DirectConnection); | - | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | // The disconnected() and error() signals may already come | - | ||||||||||||||||||
| 134 | // while calling connectToHost(). | - | ||||||||||||||||||
| 135 | // In case of a cached hostname or an IP this | - | ||||||||||||||||||
| 136 | // will then emit a signal to the user of QNetworkReply | - | ||||||||||||||||||
| 137 | // but cannot be caught because the user did not have a chance yet | - | ||||||||||||||||||
| 138 | // to connect to QNetworkReply's signals. | - | ||||||||||||||||||
| 139 | qRegisterMetaType<QAbstractSocket::SocketError>(); | - | ||||||||||||||||||
| 140 | QObject::connect(socket, SIGNAL(disconnected()), | - | ||||||||||||||||||
| 141 | this, SLOT(_q_disconnected()), | - | ||||||||||||||||||
| 142 | Qt::DirectConnection); | - | ||||||||||||||||||
| 143 | QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), | - | ||||||||||||||||||
| 144 | this, SLOT(_q_error(QAbstractSocket::SocketError)), | - | ||||||||||||||||||
| 145 | Qt::DirectConnection); | - | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 149 | QObject::connect(socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), | - | ||||||||||||||||||
| 150 | this, SLOT(_q_proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), | - | ||||||||||||||||||
| 151 | Qt::DirectConnection); | - | ||||||||||||||||||
| 152 | #endif | - | ||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 155 | QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); | - | ||||||||||||||||||
| 156 | if (sslSocket) {
| 108-646 | ||||||||||||||||||
| 157 | // won't be a sslSocket if encrypt is false | - | ||||||||||||||||||
| 158 | QObject::connect(sslSocket, SIGNAL(encrypted()), | - | ||||||||||||||||||
| 159 | this, SLOT(_q_encrypted()), | - | ||||||||||||||||||
| 160 | Qt::DirectConnection); | - | ||||||||||||||||||
| 161 | QObject::connect(sslSocket, SIGNAL(sslErrors(QList<QSslError>)), | - | ||||||||||||||||||
| 162 | this, SLOT(_q_sslErrors(QList<QSslError>)), | - | ||||||||||||||||||
| 163 | Qt::DirectConnection); | - | ||||||||||||||||||
| 164 | QObject::connect(sslSocket, SIGNAL(preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)), | - | ||||||||||||||||||
| 165 | this, SLOT(_q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)), | - | ||||||||||||||||||
| 166 | Qt::DirectConnection); | - | ||||||||||||||||||
| 167 | QObject::connect(sslSocket, SIGNAL(encryptedBytesWritten(qint64)), | - | ||||||||||||||||||
| 168 | this, SLOT(_q_encryptedBytesWritten(qint64)), | - | ||||||||||||||||||
| 169 | Qt::DirectConnection); | - | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | if (ignoreAllSslErrors)
| 11-97 | ||||||||||||||||||
| 172 | sslSocket->ignoreSslErrors(); executed 11 times by 2 tests: sslSocket->ignoreSslErrors();Executed by:
| 11 | ||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | if (!ignoreSslErrorsList.isEmpty())
| 0-108 | ||||||||||||||||||
| 175 | sslSocket->ignoreSslErrors(ignoreSslErrorsList); never executed: sslSocket->ignoreSslErrors(ignoreSslErrorsList); | 0 | ||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | if (!sslConfiguration.isNull())
| 49-59 | ||||||||||||||||||
| 178 | sslSocket->setSslConfiguration(sslConfiguration); executed 59 times by 2 tests: sslSocket->setSslConfiguration(sslConfiguration);Executed by:
| 59 | ||||||||||||||||||
| 179 | } else { executed 108 times by 3 tests: end of blockExecuted by:
| 108 | ||||||||||||||||||
| 180 | #endif // QT_NO_SSL | - | ||||||||||||||||||
| 181 | protocolHandler.reset(new QHttpProtocolHandler(this)); | - | ||||||||||||||||||
| 182 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 183 | } executed 646 times by 8 tests: end of blockExecuted by:
| 646 | ||||||||||||||||||
| 184 | #endif | - | ||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 187 | if (proxy.type() != QNetworkProxy::NoProxy)
| 101-653 | ||||||||||||||||||
| 188 | socket->setProxy(proxy); executed 101 times by 3 tests: socket->setProxy(proxy);Executed by:
| 101 | ||||||||||||||||||
| 189 | #endif | - | ||||||||||||||||||
| 190 | isInitialized = true; | - | ||||||||||||||||||
| 191 | } executed 754 times by 8 tests: end of blockExecuted by:
| 754 | ||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | void QHttpNetworkConnectionChannel::close() | - | ||||||||||||||||||
| 195 | { | - | ||||||||||||||||||
| 196 | if (!socket)
| 4-406 | ||||||||||||||||||
| 197 | state = QHttpNetworkConnectionChannel::IdleState; executed 4 times by 3 tests: state = QHttpNetworkConnectionChannel::IdleState;Executed by:
| 4 | ||||||||||||||||||
| 198 | else if (socket->state() == QAbstractSocket::UnconnectedState)
| 182-224 | ||||||||||||||||||
| 199 | state = QHttpNetworkConnectionChannel::IdleState; executed 182 times by 4 tests: state = QHttpNetworkConnectionChannel::IdleState;Executed by:
| 182 | ||||||||||||||||||
| 200 | else | - | ||||||||||||||||||
| 201 | state = QHttpNetworkConnectionChannel::ClosingState; executed 224 times by 4 tests: state = QHttpNetworkConnectionChannel::ClosingState;Executed by:
| 224 | ||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | // pendingEncrypt must only be true in between connected and encrypted states | - | ||||||||||||||||||
| 204 | pendingEncrypt = false; | - | ||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | if (socket) {
| 4-406 | ||||||||||||||||||
| 207 | // socket can be 0 since the host lookup is done from qhttpnetworkconnection.cpp while | - | ||||||||||||||||||
| 208 | // there is no socket yet. | - | ||||||||||||||||||
| 209 | socket->close(); | - | ||||||||||||||||||
| 210 | } executed 405 times by 5 tests: end of blockExecuted by:
| 405 | ||||||||||||||||||
| 211 | } executed 409 times by 5 tests: end of blockExecuted by:
| 409 | ||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | void QHttpNetworkConnectionChannel::abort() | - | ||||||||||||||||||
| 215 | { | - | ||||||||||||||||||
| 216 | if (!socket)
| 0-13 | ||||||||||||||||||
| 217 | state = QHttpNetworkConnectionChannel::IdleState; never executed: state = QHttpNetworkConnectionChannel::IdleState; | 0 | ||||||||||||||||||
| 218 | else if (socket->state() == QAbstractSocket::UnconnectedState)
| 0-13 | ||||||||||||||||||
| 219 | state = QHttpNetworkConnectionChannel::IdleState; never executed: state = QHttpNetworkConnectionChannel::IdleState; | 0 | ||||||||||||||||||
| 220 | else | - | ||||||||||||||||||
| 221 | state = QHttpNetworkConnectionChannel::ClosingState; executed 13 times by 1 test: state = QHttpNetworkConnectionChannel::ClosingState;Executed by:
| 13 | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | // pendingEncrypt must only be true in between connected and encrypted states | - | ||||||||||||||||||
| 224 | pendingEncrypt = false; | - | ||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | if (socket) {
| 0-13 | ||||||||||||||||||
| 227 | // socket can be 0 since the host lookup is done from qhttpnetworkconnection.cpp while | - | ||||||||||||||||||
| 228 | // there is no socket yet. | - | ||||||||||||||||||
| 229 | socket->abort(); | - | ||||||||||||||||||
| 230 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||
| 231 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | bool QHttpNetworkConnectionChannel::sendRequest() | - | ||||||||||||||||||
| 235 | { | - | ||||||||||||||||||
| 236 | Q_ASSERT(!protocolHandler.isNull()); | - | ||||||||||||||||||
| 237 | return protocolHandler->sendRequest(); executed 4643 times by 8 tests: return protocolHandler->sendRequest();Executed by:
| 4643 | ||||||||||||||||||
| 238 | } | - | ||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | - | |||||||||||||||||||
| 241 | void QHttpNetworkConnectionChannel::_q_receiveReply() | - | ||||||||||||||||||
| 242 | { | - | ||||||||||||||||||
| 243 | Q_ASSERT(!protocolHandler.isNull()); | - | ||||||||||||||||||
| 244 | protocolHandler->_q_receiveReply(); | - | ||||||||||||||||||
| 245 | } executed 202 times by 2 tests: end of blockExecuted by:
| 202 | ||||||||||||||||||
| 246 | - | |||||||||||||||||||
| 247 | void QHttpNetworkConnectionChannel::_q_readyRead() | - | ||||||||||||||||||
| 248 | { | - | ||||||||||||||||||
| 249 | Q_ASSERT(!protocolHandler.isNull()); | - | ||||||||||||||||||
| 250 | protocolHandler->_q_readyRead(); | - | ||||||||||||||||||
| 251 | } executed 11090 times by 7 tests: end of blockExecuted by:
| 11090 | ||||||||||||||||||
| 252 | - | |||||||||||||||||||
| 253 | // called when unexpectedly reading a -1 or when data is expected but socket is closed | - | ||||||||||||||||||
| 254 | void QHttpNetworkConnectionChannel::handleUnexpectedEOF() | - | ||||||||||||||||||
| 255 | { | - | ||||||||||||||||||
| 256 | Q_ASSERT(reply); | - | ||||||||||||||||||
| 257 | if (reconnectAttempts <= 0) {
| 27-65 | ||||||||||||||||||
| 258 | // too many errors reading/receiving/parsing the status, close the socket and emit error | - | ||||||||||||||||||
| 259 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 260 | close(); | - | ||||||||||||||||||
| 261 | reply->d_func()->errorString = connection->d_func()->errorDetail(QNetworkReply::RemoteHostClosedError, socket); | - | ||||||||||||||||||
| 262 | emit reply->finishedWithError(QNetworkReply::RemoteHostClosedError, reply->d_func()->errorString); | - | ||||||||||||||||||
| 263 | reply = 0; | - | ||||||||||||||||||
| 264 | if (protocolHandler)
| 0-27 | ||||||||||||||||||
| 265 | protocolHandler->setReply(0); executed 27 times by 2 tests: protocolHandler->setReply(0);Executed by:
| 27 | ||||||||||||||||||
| 266 | request = QHttpNetworkRequest(); | - | ||||||||||||||||||
| 267 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 268 | } else { executed 27 times by 2 tests: end of blockExecuted by:
| 27 | ||||||||||||||||||
| 269 | reconnectAttempts--; | - | ||||||||||||||||||
| 270 | reply->d_func()->clear(); | - | ||||||||||||||||||
| 271 | reply->d_func()->connection = connection; | - | ||||||||||||||||||
| 272 | reply->d_func()->connectionChannel = this; | - | ||||||||||||||||||
| 273 | closeAndResendCurrentRequest(); | - | ||||||||||||||||||
| 274 | } executed 65 times by 2 tests: end of blockExecuted by:
| 65 | ||||||||||||||||||
| 275 | } | - | ||||||||||||||||||
| 276 | - | |||||||||||||||||||
| 277 | bool QHttpNetworkConnectionChannel::ensureConnection() | - | ||||||||||||||||||
| 278 | { | - | ||||||||||||||||||
| 279 | if (!isInitialized)
| 754-1600 | ||||||||||||||||||
| 280 | init(); executed 754 times by 8 tests: init();Executed by:
| 754 | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | QAbstractSocket::SocketState socketState = socket->state(); | - | ||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | // resend this request after we receive the disconnected signal | - | ||||||||||||||||||
| 285 | // If !socket->isOpen() then we have already called close() on the socket, but there was still a | - | ||||||||||||||||||
| 286 | // pending connectToHost() for which we hadn't seen a connected() signal, yet. The connected() | - | ||||||||||||||||||
| 287 | // has now arrived (as indicated by socketState != ClosingState), but we cannot send anything on | - | ||||||||||||||||||
| 288 | // such a socket anymore. | - | ||||||||||||||||||
| 289 | if (socketState == QAbstractSocket::ClosingState ||
| 0-2354 | ||||||||||||||||||
| 290 | (socketState != QAbstractSocket::UnconnectedState && !socket->isOpen())) {
| 0-1432 | ||||||||||||||||||
| 291 | if (reply)
| 0 | ||||||||||||||||||
| 292 | resendCurrent = true; never executed: resendCurrent = true; | 0 | ||||||||||||||||||
| 293 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 294 | } | - | ||||||||||||||||||
| 295 | - | |||||||||||||||||||
| 296 | // already trying to connect? | - | ||||||||||||||||||
| 297 | if (socketState == QAbstractSocket::HostLookupState ||
| 0-2354 | ||||||||||||||||||
| 298 | socketState == QAbstractSocket::ConnectingState) {
| 3-2351 | ||||||||||||||||||
| 299 | return false; executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||||||||
| 300 | } | - | ||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | // make sure that this socket is in a connected state, if not initiate | - | ||||||||||||||||||
| 303 | // connection to the host. | - | ||||||||||||||||||
| 304 | if (socketState != QAbstractSocket::ConnectedState) {
| 922-1429 | ||||||||||||||||||
| 305 | // connect to the host if not already connected. | - | ||||||||||||||||||
| 306 | state = QHttpNetworkConnectionChannel::ConnectingState; | - | ||||||||||||||||||
| 307 | pendingEncrypt = ssl; | - | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | // reset state | - | ||||||||||||||||||
| 310 | pipeliningSupported = PipeliningSupportUnknown; | - | ||||||||||||||||||
| 311 | authenticationCredentialsSent = false; | - | ||||||||||||||||||
| 312 | proxyCredentialsSent = false; | - | ||||||||||||||||||
| 313 | authenticator.detach(); | - | ||||||||||||||||||
| 314 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(authenticator); | - | ||||||||||||||||||
| 315 | priv->hasFailed = false; | - | ||||||||||||||||||
| 316 | proxyAuthenticator.detach(); | - | ||||||||||||||||||
| 317 | priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator); | - | ||||||||||||||||||
| 318 | priv->hasFailed = false; | - | ||||||||||||||||||
| 319 | - | |||||||||||||||||||
| 320 | // This workaround is needed since we use QAuthenticator for NTLM authentication. The "phase == Done" | - | ||||||||||||||||||
| 321 | // is the usual criteria for emitting authentication signals. The "phase" is set to "Done" when the | - | ||||||||||||||||||
| 322 | // last header for Authorization is generated by the QAuthenticator. Basic & Digest logic does not | - | ||||||||||||||||||
| 323 | // check the "phase" for generating the Authorization header. NTLM authentication is a two stage | - | ||||||||||||||||||
| 324 | // process & needs the "phase". To make sure the QAuthenticator uses the current username/password | - | ||||||||||||||||||
| 325 | // the phase is reset to Start. | - | ||||||||||||||||||
| 326 | priv = QAuthenticatorPrivate::getPrivate(authenticator); | - | ||||||||||||||||||
| 327 | if (priv && priv->phase == QAuthenticatorPrivate::Done)
| 0-922 | ||||||||||||||||||
| 328 | priv->phase = QAuthenticatorPrivate::Start; never executed: priv->phase = QAuthenticatorPrivate::Start; | 0 | ||||||||||||||||||
| 329 | priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator); | - | ||||||||||||||||||
| 330 | if (priv && priv->phase == QAuthenticatorPrivate::Done)
| 0-922 | ||||||||||||||||||
| 331 | priv->phase = QAuthenticatorPrivate::Start; never executed: priv->phase = QAuthenticatorPrivate::Start; | 0 | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | QString connectHost = connection->d_func()->hostName; | - | ||||||||||||||||||
| 334 | quint16 connectPort = connection->d_func()->port; | - | ||||||||||||||||||
| 335 | - | |||||||||||||||||||
| 336 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 337 | // HTTPS always use transparent proxy. | - | ||||||||||||||||||
| 338 | if (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy && !ssl) {
| 0-827 | ||||||||||||||||||
| 339 | connectHost = connection->d_func()->networkProxy.hostName(); | - | ||||||||||||||||||
| 340 | connectPort = connection->d_func()->networkProxy.port(); | - | ||||||||||||||||||
| 341 | } executed 95 times by 1 test: end of blockExecuted by:
| 95 | ||||||||||||||||||
| 342 | if (socket->proxy().type() == QNetworkProxy::HttpProxy) {
| 23-899 | ||||||||||||||||||
| 343 | // Make user-agent field available to HTTP proxy socket engine (QTBUG-17223) | - | ||||||||||||||||||
| 344 | QByteArray value; | - | ||||||||||||||||||
| 345 | // ensureConnection is called before any request has been assigned, but can also be called again if reconnecting | - | ||||||||||||||||||
| 346 | if (request.url().isEmpty())
| 2-21 | ||||||||||||||||||
| 347 | value = connection->d_func()->predictNextRequest().headerField("user-agent"); executed 21 times by 2 tests: value = connection->d_func()->predictNextRequest().headerField("user-agent");Executed by:
| 21 | ||||||||||||||||||
| 348 | else | - | ||||||||||||||||||
| 349 | value = request.headerField("user-agent"); executed 2 times by 1 test: value = request.headerField("user-agent");Executed by:
| 2 | ||||||||||||||||||
| 350 | if (!value.isEmpty()) {
| 6-17 | ||||||||||||||||||
| 351 | QNetworkProxy proxy(socket->proxy()); | - | ||||||||||||||||||
| 352 | proxy.setRawHeader("User-Agent", value); //detaches | - | ||||||||||||||||||
| 353 | socket->setProxy(proxy); | - | ||||||||||||||||||
| 354 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 355 | } executed 23 times by 2 tests: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 356 | #endif | - | ||||||||||||||||||
| 357 | if (ssl) {
| 127-795 | ||||||||||||||||||
| 358 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 359 | QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); | - | ||||||||||||||||||
| 360 | - | |||||||||||||||||||
| 361 | // check whether we can re-use an existing SSL session | - | ||||||||||||||||||
| 362 | // (meaning another socket in this connection has already | - | ||||||||||||||||||
| 363 | // performed a full handshake) | - | ||||||||||||||||||
| 364 | if (!connection->sslContext().isNull())
| 26-101 | ||||||||||||||||||
| 365 | QSslSocketPrivate::checkSettingSslContext(sslSocket, connection->sslContext()); executed 26 times by 1 test: QSslSocketPrivate::checkSettingSslContext(sslSocket, connection->sslContext());Executed by:
| 26 | ||||||||||||||||||
| 366 | - | |||||||||||||||||||
| 367 | sslSocket->connectToHostEncrypted(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference); | - | ||||||||||||||||||
| 368 | if (ignoreAllSslErrors)
| 21-106 | ||||||||||||||||||
| 369 | sslSocket->ignoreSslErrors(); executed 21 times by 2 tests: sslSocket->ignoreSslErrors();Executed by:
| 21 | ||||||||||||||||||
| 370 | sslSocket->ignoreSslErrors(ignoreSslErrorsList); | - | ||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | // limit the socket read buffer size. we will read everything into | - | ||||||||||||||||||
| 373 | // the QHttpNetworkReply anyway, so let's grow only that and not | - | ||||||||||||||||||
| 374 | // here and there. | - | ||||||||||||||||||
| 375 | socket->setReadBufferSize(64*1024); | - | ||||||||||||||||||
| 376 | #else | - | ||||||||||||||||||
| 377 | // Need to dequeue the request so that we can emit the error. | - | ||||||||||||||||||
| 378 | if (!reply) | - | ||||||||||||||||||
| 379 | connection->d_func()->dequeueRequest(socket); | - | ||||||||||||||||||
| 380 | connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ProtocolUnknownError); | - | ||||||||||||||||||
| 381 | #endif | - | ||||||||||||||||||
| 382 | } else { executed 127 times by 3 tests: end of blockExecuted by:
| 127 | ||||||||||||||||||
| 383 | // In case of no proxy we can use the Unbuffered QTcpSocket | - | ||||||||||||||||||
| 384 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 385 | if (connection->d_func()->networkProxy.type() == QNetworkProxy::NoProxy
| 95-700 | ||||||||||||||||||
| 386 | && connection->cacheProxy().type() == QNetworkProxy::NoProxy
| 0-700 | ||||||||||||||||||
| 387 | && connection->transparentProxy().type() == QNetworkProxy::NoProxy) {
| 86-614 | ||||||||||||||||||
| 388 | #endif | - | ||||||||||||||||||
| 389 | socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite | QIODevice::Unbuffered, networkLayerPreference); | - | ||||||||||||||||||
| 390 | // For an Unbuffered QTcpSocket, the read buffer size has a special meaning. | - | ||||||||||||||||||
| 391 | socket->setReadBufferSize(1*1024); | - | ||||||||||||||||||
| 392 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 393 | } else { executed 614 times by 8 tests: end of blockExecuted by:
| 614 | ||||||||||||||||||
| 394 | socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference); | - | ||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | // limit the socket read buffer size. we will read everything into | - | ||||||||||||||||||
| 397 | // the QHttpNetworkReply anyway, so let's grow only that and not | - | ||||||||||||||||||
| 398 | // here and there. | - | ||||||||||||||||||
| 399 | socket->setReadBufferSize(64*1024); | - | ||||||||||||||||||
| 400 | } executed 181 times by 2 tests: end of blockExecuted by:
| 181 | ||||||||||||||||||
| 401 | #endif | - | ||||||||||||||||||
| 402 | } | - | ||||||||||||||||||
| 403 | return false; executed 922 times by 8 tests: return false;Executed by:
| 922 | ||||||||||||||||||
| 404 | } | - | ||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | // This code path for ConnectedState | - | ||||||||||||||||||
| 407 | if (pendingEncrypt) {
| 0-1429 | ||||||||||||||||||
| 408 | // Let's only be really connected when we have received the encrypted() signal. Else the state machine seems to mess up | - | ||||||||||||||||||
| 409 | // and corrupt the things sent to the server. | - | ||||||||||||||||||
| 410 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 411 | } | - | ||||||||||||||||||
| 412 | - | |||||||||||||||||||
| 413 | return true; executed 1429 times by 8 tests: return true;Executed by:
| 1429 | ||||||||||||||||||
| 414 | } | - | ||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | void QHttpNetworkConnectionChannel::allDone() | - | ||||||||||||||||||
| 417 | { | - | ||||||||||||||||||
| 418 | Q_ASSERT(reply); | - | ||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | if (!reply) {
| 0-1762 | ||||||||||||||||||
| 421 | qWarning("QHttpNetworkConnectionChannel::allDone() called without reply. Please report at http://bugreports.qt.io/"); | - | ||||||||||||||||||
| 422 | return; never executed: return; | 0 | ||||||||||||||||||
| 423 | } | - | ||||||||||||||||||
| 424 | - | |||||||||||||||||||
| 425 | // while handling 401 & 407, we might reset the status code, so save this. | - | ||||||||||||||||||
| 426 | bool emitFinished = reply->d_func()->shouldEmitSignals(); | - | ||||||||||||||||||
| 427 | bool connectionCloseEnabled = reply->d_func()->isConnectionCloseEnabled(); | - | ||||||||||||||||||
| 428 | detectPipeliningSupport(); | - | ||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | handleStatus(); | - | ||||||||||||||||||
| 431 | // handleStatus() might have removed the reply because it already called connection->emitReplyError() | - | ||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | // queue the finished signal, this is required since we might send new requests from | - | ||||||||||||||||||
| 434 | // slot connected to it. The socket will not fire readyRead signal, if we are already | - | ||||||||||||||||||
| 435 | // in the slot connected to readyRead | - | ||||||||||||||||||
| 436 | if (reply && emitFinished)
| 2-1760 | ||||||||||||||||||
| 437 | QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection); executed 1405 times by 7 tests: QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection);Executed by:
| 1405 | ||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | - | |||||||||||||||||||
| 440 | // reset the reconnection attempts after we receive a complete reply. | - | ||||||||||||||||||
| 441 | // in case of failures, each channel will attempt two reconnects before emitting error. | - | ||||||||||||||||||
| 442 | reconnectAttempts = reconnectAttemptsDefault; | - | ||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | // now the channel can be seen as free/idle again, all signal emissions for the reply have been done | - | ||||||||||||||||||
| 445 | if (state != QHttpNetworkConnectionChannel::ClosingState)
| 0-1762 | ||||||||||||||||||
| 446 | state = QHttpNetworkConnectionChannel::IdleState; executed 1762 times by 7 tests: state = QHttpNetworkConnectionChannel::IdleState;Executed by:
| 1762 | ||||||||||||||||||
| 447 | - | |||||||||||||||||||
| 448 | // if it does not need to be sent again we can set it to 0 | - | ||||||||||||||||||
| 449 | // the previous code did not do that and we had problems with accidental re-sending of a | - | ||||||||||||||||||
| 450 | // finished request. | - | ||||||||||||||||||
| 451 | // Note that this may trigger a segfault at some other point. But then we can fix the underlying | - | ||||||||||||||||||
| 452 | // problem. | - | ||||||||||||||||||
| 453 | if (!resendCurrent) {
| 325-1437 | ||||||||||||||||||
| 454 | request = QHttpNetworkRequest(); | - | ||||||||||||||||||
| 455 | reply = 0; | - | ||||||||||||||||||
| 456 | protocolHandler->setReply(0); | - | ||||||||||||||||||
| 457 | } executed 1437 times by 7 tests: end of blockExecuted by:
| 1437 | ||||||||||||||||||
| 458 | - | |||||||||||||||||||
| 459 | // move next from pipeline to current request | - | ||||||||||||||||||
| 460 | if (!alreadyPipelinedRequests.isEmpty()) {
| 402-1360 | ||||||||||||||||||
| 461 | if (resendCurrent || connectionCloseEnabled || socket->state() != QAbstractSocket::ConnectedState) {
| 0-402 | ||||||||||||||||||
| 462 | // move the pipelined ones back to the main queue | - | ||||||||||||||||||
| 463 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 464 | close(); | - | ||||||||||||||||||
| 465 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 466 | // there were requests pipelined in and we can continue | - | ||||||||||||||||||
| 467 | HttpMessagePair messagePair = alreadyPipelinedRequests.takeFirst(); | - | ||||||||||||||||||
| 468 | - | |||||||||||||||||||
| 469 | request = messagePair.first; | - | ||||||||||||||||||
| 470 | reply = messagePair.second; | - | ||||||||||||||||||
| 471 | protocolHandler->setReply(messagePair.second); | - | ||||||||||||||||||
| 472 | state = QHttpNetworkConnectionChannel::ReadingState; | - | ||||||||||||||||||
| 473 | resendCurrent = false; | - | ||||||||||||||||||
| 474 | - | |||||||||||||||||||
| 475 | written = 0; // message body, excluding the header, irrelevant here | - | ||||||||||||||||||
| 476 | bytesTotal = 0; // message body total, excluding the header, irrelevant here | - | ||||||||||||||||||
| 477 | - | |||||||||||||||||||
| 478 | // pipeline even more | - | ||||||||||||||||||
| 479 | connection->d_func()->fillPipeline(socket); | - | ||||||||||||||||||
| 480 | - | |||||||||||||||||||
| 481 | // continue reading | - | ||||||||||||||||||
| 482 | //_q_receiveReply(); | - | ||||||||||||||||||
| 483 | // this was wrong, allDone gets called from that function anyway. | - | ||||||||||||||||||
| 484 | } executed 402 times by 2 tests: end of blockExecuted by:
| 402 | ||||||||||||||||||
| 485 | } else if (alreadyPipelinedRequests.isEmpty() && socket->bytesAvailable() > 0) {
| 0-1360 | ||||||||||||||||||
| 486 | // this is weird. we had nothing pipelined but still bytes available. better close it. | - | ||||||||||||||||||
| 487 | close(); | - | ||||||||||||||||||
| 488 | - | |||||||||||||||||||
| 489 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 490 | } else if (alreadyPipelinedRequests.isEmpty()) { never executed: end of block
| 0-1360 | ||||||||||||||||||
| 491 | if (connectionCloseEnabled)
| 185-1175 | ||||||||||||||||||
| 492 | if (socket->state() != QAbstractSocket::UnconnectedState)
| 60-125 | ||||||||||||||||||
| 493 | close(); executed 125 times by 2 tests: close();Executed by:
| 125 | ||||||||||||||||||
| 494 | if (qobject_cast<QHttpNetworkConnection*>(connection))
| 0-1360 | ||||||||||||||||||
| 495 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 1360 times by 7 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);Executed by:
| 1360 | ||||||||||||||||||
| 496 | } executed 1360 times by 7 tests: end of blockExecuted by:
| 1360 | ||||||||||||||||||
| 497 | } executed 1762 times by 7 tests: end of blockExecuted by:
| 1762 | ||||||||||||||||||
| 498 | - | |||||||||||||||||||
| 499 | void QHttpNetworkConnectionChannel::detectPipeliningSupport() | - | ||||||||||||||||||
| 500 | { | - | ||||||||||||||||||
| 501 | Q_ASSERT(reply); | - | ||||||||||||||||||
| 502 | // detect HTTP Pipelining support | - | ||||||||||||||||||
| 503 | QByteArray serverHeaderField; | - | ||||||||||||||||||
| 504 | if ( | - | ||||||||||||||||||
| 505 | // check for HTTP/1.1 | - | ||||||||||||||||||
| 506 | (reply->d_func()->majorVersion == 1 && reply->d_func()->minorVersion == 1)
| 0-1762 | ||||||||||||||||||
| 507 | // check for not having connection close | - | ||||||||||||||||||
| 508 | && (!reply->d_func()->isConnectionCloseEnabled())
| 4-1517 | ||||||||||||||||||
| 509 | // check if it is still connected | - | ||||||||||||||||||
| 510 | && (socket->state() == QAbstractSocket::ConnectedState)
| 10-1507 | ||||||||||||||||||
| 511 | // check for broken servers in server reply header | - | ||||||||||||||||||
| 512 | // this is adapted from http://mxr.mozilla.org/firefox/ident?i=SupportsPipelining | - | ||||||||||||||||||
| 513 | && (serverHeaderField = reply->headerField("Server"), !serverHeaderField.contains("Microsoft-IIS/4."))
| 0-1507 | ||||||||||||||||||
| 514 | && (!serverHeaderField.contains("Microsoft-IIS/5."))
| 0-1507 | ||||||||||||||||||
| 515 | && (!serverHeaderField.contains("Netscape-Enterprise/3."))
| 0-1507 | ||||||||||||||||||
| 516 | // this is adpoted from the knowledge of the Nokia 7.x browser team (DEF143319) | - | ||||||||||||||||||
| 517 | && (!serverHeaderField.contains("WebLogic"))
| 0-1507 | ||||||||||||||||||
| 518 | && (!serverHeaderField.startsWith("Rocket")) // a Python Web Server, see Web2py.com
| 0-1507 | ||||||||||||||||||
| 519 | ) { | - | ||||||||||||||||||
| 520 | pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningProbablySupported; | - | ||||||||||||||||||
| 521 | } else { executed 1507 times by 7 tests: end of blockExecuted by:
| 1507 | ||||||||||||||||||
| 522 | pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown; | - | ||||||||||||||||||
| 523 | } executed 255 times by 2 tests: end of blockExecuted by:
| 255 | ||||||||||||||||||
| 524 | } | - | ||||||||||||||||||
| 525 | - | |||||||||||||||||||
| 526 | // called when the connection broke and we need to queue some pipelined requests again | - | ||||||||||||||||||
| 527 | void QHttpNetworkConnectionChannel::requeueCurrentlyPipelinedRequests() | - | ||||||||||||||||||
| 528 | { | - | ||||||||||||||||||
| 529 | for (int i = 0; i < alreadyPipelinedRequests.length(); i++)
| 0-136 | ||||||||||||||||||
| 530 | connection->d_func()->requeueRequest(alreadyPipelinedRequests.at(i)); never executed: connection->d_func()->requeueRequest(alreadyPipelinedRequests.at(i)); | 0 | ||||||||||||||||||
| 531 | alreadyPipelinedRequests.clear(); | - | ||||||||||||||||||
| 532 | - | |||||||||||||||||||
| 533 | // only run when the QHttpNetworkConnection is not currently being destructed, e.g. | - | ||||||||||||||||||
| 534 | // this function is called from _q_disconnected which is called because | - | ||||||||||||||||||
| 535 | // of ~QHttpNetworkConnectionPrivate | - | ||||||||||||||||||
| 536 | if (qobject_cast<QHttpNetworkConnection*>(connection))
| 0-136 | ||||||||||||||||||
| 537 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 136 times by 3 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);Executed by:
| 136 | ||||||||||||||||||
| 538 | } executed 136 times by 3 tests: end of blockExecuted by:
| 136 | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | void QHttpNetworkConnectionChannel::handleStatus() | - | ||||||||||||||||||
| 541 | { | - | ||||||||||||||||||
| 542 | Q_ASSERT(socket); | - | ||||||||||||||||||
| 543 | Q_ASSERT(reply); | - | ||||||||||||||||||
| 544 | - | |||||||||||||||||||
| 545 | int statusCode = reply->statusCode(); | - | ||||||||||||||||||
| 546 | bool resend = false; | - | ||||||||||||||||||
| 547 | - | |||||||||||||||||||
| 548 | switch (statusCode) { | - | ||||||||||||||||||
| 549 | case 301: executed 3 times by 1 test: case 301:Executed by:
| 3 | ||||||||||||||||||
| 550 | case 302: never executed: case 302: | 0 | ||||||||||||||||||
| 551 | case 303: never executed: case 303: | 0 | ||||||||||||||||||
| 552 | case 305: never executed: case 305: | 0 | ||||||||||||||||||
| 553 | case 307: { executed 6 times by 1 test: case 307:Executed by:
| 6 | ||||||||||||||||||
| 554 | // Parse the response headers and get the "location" url | - | ||||||||||||||||||
| 555 | QUrl redirectUrl = connection->d_func()->parseRedirectResponse(socket, reply); | - | ||||||||||||||||||
| 556 | if (redirectUrl.isValid())
| 4-5 | ||||||||||||||||||
| 557 | reply->setRedirectUrl(redirectUrl); executed 5 times by 1 test: reply->setRedirectUrl(redirectUrl);Executed by:
| 5 | ||||||||||||||||||
| 558 | - | |||||||||||||||||||
| 559 | if (qobject_cast<QHttpNetworkConnection *>(connection))
| 0-9 | ||||||||||||||||||
| 560 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 9 times by 2 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);Executed by:
| 9 | ||||||||||||||||||
| 561 | break; executed 9 times by 2 tests: break;Executed by:
| 9 | ||||||||||||||||||
| 562 | } | - | ||||||||||||||||||
| 563 | case 401: // auth required executed 302 times by 2 tests: case 401:Executed by:
| 302 | ||||||||||||||||||
| 564 | case 407: // proxy auth required executed 54 times by 1 test: case 407:Executed by:
| 54 | ||||||||||||||||||
| 565 | if (connection->d_func()->handleAuthenticateChallenge(socket, reply, (statusCode == 407), resend)) {
| 3-353 | ||||||||||||||||||
| 566 | if (resend) {
| 38-315 | ||||||||||||||||||
| 567 | if (!resetUploadData())
| 1-314 | ||||||||||||||||||
| 568 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||
| 569 | - | |||||||||||||||||||
| 570 | reply->d_func()->eraseData(); | - | ||||||||||||||||||
| 571 | - | |||||||||||||||||||
| 572 | if (alreadyPipelinedRequests.isEmpty()) {
| 0-314 | ||||||||||||||||||
| 573 | // this does a re-send without closing the connection | - | ||||||||||||||||||
| 574 | resendCurrent = true; | - | ||||||||||||||||||
| 575 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 576 | } else { executed 314 times by 2 tests: end of blockExecuted by:
| 314 | ||||||||||||||||||
| 577 | // we had requests pipelined.. better close the connection in closeAndResendCurrentRequest | - | ||||||||||||||||||
| 578 | closeAndResendCurrentRequest(); | - | ||||||||||||||||||
| 579 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 580 | } never executed: end of block | 0 | ||||||||||||||||||
| 581 | } else { | - | ||||||||||||||||||
| 582 | //authentication cancelled, close the channel. | - | ||||||||||||||||||
| 583 | close(); | - | ||||||||||||||||||
| 584 | } executed 38 times by 2 tests: end of blockExecuted by:
| 38 | ||||||||||||||||||
| 585 | } else { | - | ||||||||||||||||||
| 586 | emit reply->headerChanged(); | - | ||||||||||||||||||
| 587 | emit reply->readyRead(); | - | ||||||||||||||||||
| 588 | QNetworkReply::NetworkError errorCode = (statusCode == 407)
| 1-2 | ||||||||||||||||||
| 589 | ? QNetworkReply::ProxyAuthenticationRequiredError | - | ||||||||||||||||||
| 590 | : QNetworkReply::AuthenticationRequiredError; | - | ||||||||||||||||||
| 591 | reply->d_func()->errorString = connection->d_func()->errorDetail(errorCode, socket); | - | ||||||||||||||||||
| 592 | emit reply->finishedWithError(errorCode, reply->d_func()->errorString); | - | ||||||||||||||||||
| 593 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 594 | break; executed 355 times by 2 tests: break;Executed by:
| 355 | ||||||||||||||||||
| 595 | default: executed 1397 times by 6 tests: default:Executed by:
| 1397 | ||||||||||||||||||
| 596 | if (qobject_cast<QHttpNetworkConnection*>(connection))
| 0-1397 | ||||||||||||||||||
| 597 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 1397 times by 6 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);Executed by:
| 1397 | ||||||||||||||||||
| 598 | } executed 1397 times by 6 tests: end of blockExecuted by:
| 1397 | ||||||||||||||||||
| 599 | } | - | ||||||||||||||||||
| 600 | - | |||||||||||||||||||
| 601 | bool QHttpNetworkConnectionChannel::resetUploadData() | - | ||||||||||||||||||
| 602 | { | - | ||||||||||||||||||
| 603 | if (!reply) {
| 9-547 | ||||||||||||||||||
| 604 | //this happens if server closes connection while QHttpNetworkConnectionPrivate::_q_startNextRequest is pending | - | ||||||||||||||||||
| 605 | return false; executed 9 times by 2 tests: return false;Executed by:
| 9 | ||||||||||||||||||
| 606 | } | - | ||||||||||||||||||
| 607 | QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice(); | - | ||||||||||||||||||
| 608 | if (!uploadByteDevice)
| 127-420 | ||||||||||||||||||
| 609 | return true; executed 420 times by 2 tests: return true;Executed by:
| 420 | ||||||||||||||||||
| 610 | - | |||||||||||||||||||
| 611 | if (uploadByteDevice->reset()) {
| 1-126 | ||||||||||||||||||
| 612 | written = 0; | - | ||||||||||||||||||
| 613 | return true; executed 126 times by 1 test: return true;Executed by:
| 126 | ||||||||||||||||||
| 614 | } else { | - | ||||||||||||||||||
| 615 | connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ContentReSendError); | - | ||||||||||||||||||
| 616 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||
| 617 | } | - | ||||||||||||||||||
| 618 | } | - | ||||||||||||||||||
| 619 | - | |||||||||||||||||||
| 620 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 621 | - | |||||||||||||||||||
| 622 | void QHttpNetworkConnectionChannel::setProxy(const QNetworkProxy &networkProxy) | - | ||||||||||||||||||
| 623 | { | - | ||||||||||||||||||
| 624 | if (socket)
| 0-3251 | ||||||||||||||||||
| 625 | socket->setProxy(networkProxy); never executed: socket->setProxy(networkProxy); | 0 | ||||||||||||||||||
| 626 | - | |||||||||||||||||||
| 627 | proxy = networkProxy; | - | ||||||||||||||||||
| 628 | } executed 3251 times by 8 tests: end of blockExecuted by:
| 3251 | ||||||||||||||||||
| 629 | - | |||||||||||||||||||
| 630 | #endif | - | ||||||||||||||||||
| 631 | - | |||||||||||||||||||
| 632 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 633 | - | |||||||||||||||||||
| 634 | void QHttpNetworkConnectionChannel::ignoreSslErrors() | - | ||||||||||||||||||
| 635 | { | - | ||||||||||||||||||
| 636 | if (socket)
| 33-141 | ||||||||||||||||||
| 637 | static_cast<QSslSocket *>(socket)->ignoreSslErrors(); executed 33 times by 3 tests: static_cast<QSslSocket *>(socket)->ignoreSslErrors();Executed by:
| 33 | ||||||||||||||||||
| 638 | - | |||||||||||||||||||
| 639 | ignoreAllSslErrors = true; | - | ||||||||||||||||||
| 640 | } executed 174 times by 3 tests: end of blockExecuted by:
| 174 | ||||||||||||||||||
| 641 | - | |||||||||||||||||||
| 642 | - | |||||||||||||||||||
| 643 | void QHttpNetworkConnectionChannel::ignoreSslErrors(const QList<QSslError> &errors) | - | ||||||||||||||||||
| 644 | { | - | ||||||||||||||||||
| 645 | if (socket)
| 6-30 | ||||||||||||||||||
| 646 | static_cast<QSslSocket *>(socket)->ignoreSslErrors(errors); executed 6 times by 1 test: static_cast<QSslSocket *>(socket)->ignoreSslErrors(errors);Executed by:
| 6 | ||||||||||||||||||
| 647 | - | |||||||||||||||||||
| 648 | ignoreSslErrorsList = errors; | - | ||||||||||||||||||
| 649 | } executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 650 | - | |||||||||||||||||||
| 651 | void QHttpNetworkConnectionChannel::setSslConfiguration(const QSslConfiguration &config) | - | ||||||||||||||||||
| 652 | { | - | ||||||||||||||||||
| 653 | if (socket)
| 0-287 | ||||||||||||||||||
| 654 | static_cast<QSslSocket *>(socket)->setSslConfiguration(config); never executed: static_cast<QSslSocket *>(socket)->setSslConfiguration(config); | 0 | ||||||||||||||||||
| 655 | - | |||||||||||||||||||
| 656 | sslConfiguration = config; | - | ||||||||||||||||||
| 657 | } executed 287 times by 2 tests: end of blockExecuted by:
| 287 | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | #endif | - | ||||||||||||||||||
| 660 | - | |||||||||||||||||||
| 661 | void QHttpNetworkConnectionChannel::pipelineInto(HttpMessagePair &pair) | - | ||||||||||||||||||
| 662 | { | - | ||||||||||||||||||
| 663 | // this is only called for simple GET | - | ||||||||||||||||||
| 664 | - | |||||||||||||||||||
| 665 | QHttpNetworkRequest &request = pair.first; | - | ||||||||||||||||||
| 666 | QHttpNetworkReply *reply = pair.second; | - | ||||||||||||||||||
| 667 | reply->d_func()->clear(); | - | ||||||||||||||||||
| 668 | reply->d_func()->connection = connection; | - | ||||||||||||||||||
| 669 | reply->d_func()->connectionChannel = this; | - | ||||||||||||||||||
| 670 | reply->d_func()->autoDecompress = request.d->autoDecompress; | - | ||||||||||||||||||
| 671 | reply->d_func()->pipeliningUsed = true; | - | ||||||||||||||||||
| 672 | - | |||||||||||||||||||
| 673 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 674 | pipeline.append(QHttpNetworkRequestPrivate::header(request, | - | ||||||||||||||||||
| 675 | (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy))); | - | ||||||||||||||||||
| 676 | #else | - | ||||||||||||||||||
| 677 | pipeline.append(QHttpNetworkRequestPrivate::header(request, false)); | - | ||||||||||||||||||
| 678 | #endif | - | ||||||||||||||||||
| 679 | - | |||||||||||||||||||
| 680 | alreadyPipelinedRequests.append(pair); | - | ||||||||||||||||||
| 681 | - | |||||||||||||||||||
| 682 | // pipelineFlush() needs to be called at some point afterwards | - | ||||||||||||||||||
| 683 | } executed 402 times by 2 tests: end of blockExecuted by:
| 402 | ||||||||||||||||||
| 684 | - | |||||||||||||||||||
| 685 | void QHttpNetworkConnectionChannel::pipelineFlush() | - | ||||||||||||||||||
| 686 | { | - | ||||||||||||||||||
| 687 | if (pipeline.isEmpty())
| 11-195 | ||||||||||||||||||
| 688 | return; executed 11 times by 1 test: return;Executed by:
| 11 | ||||||||||||||||||
| 689 | - | |||||||||||||||||||
| 690 | // The goal of this is so that we have everything in one TCP packet. | - | ||||||||||||||||||
| 691 | // For the Unbuffered QTcpSocket this is manually needed, the buffered | - | ||||||||||||||||||
| 692 | // QTcpSocket does it automatically. | - | ||||||||||||||||||
| 693 | // Also, sometimes the OS does it for us (Nagle's algorithm) but that | - | ||||||||||||||||||
| 694 | // happens only sometimes. | - | ||||||||||||||||||
| 695 | socket->write(pipeline); | - | ||||||||||||||||||
| 696 | pipeline.clear(); | - | ||||||||||||||||||
| 697 | } executed 195 times by 2 tests: end of blockExecuted by:
| 195 | ||||||||||||||||||
| 698 | - | |||||||||||||||||||
| 699 | - | |||||||||||||||||||
| 700 | void QHttpNetworkConnectionChannel::closeAndResendCurrentRequest() | - | ||||||||||||||||||
| 701 | { | - | ||||||||||||||||||
| 702 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 703 | close(); | - | ||||||||||||||||||
| 704 | if (reply)
| 0-65 | ||||||||||||||||||
| 705 | resendCurrent = true; executed 65 times by 2 tests: resendCurrent = true;Executed by:
| 65 | ||||||||||||||||||
| 706 | if (qobject_cast<QHttpNetworkConnection*>(connection))
| 0-65 | ||||||||||||||||||
| 707 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 65 times by 2 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);Executed by:
| 65 | ||||||||||||||||||
| 708 | } executed 65 times by 2 tests: end of blockExecuted by:
| 65 | ||||||||||||||||||
| 709 | - | |||||||||||||||||||
| 710 | void QHttpNetworkConnectionChannel::resendCurrentRequest() | - | ||||||||||||||||||
| 711 | { | - | ||||||||||||||||||
| 712 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 713 | if (reply)
| 6-27 | ||||||||||||||||||
| 714 | resendCurrent = true; executed 27 times by 2 tests: resendCurrent = true;Executed by:
| 27 | ||||||||||||||||||
| 715 | if (qobject_cast<QHttpNetworkConnection*>(connection))
| 0-33 | ||||||||||||||||||
| 716 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 33 times by 2 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);Executed by:
| 33 | ||||||||||||||||||
| 717 | } executed 33 times by 2 tests: end of blockExecuted by:
| 33 | ||||||||||||||||||
| 718 | - | |||||||||||||||||||
| 719 | bool QHttpNetworkConnectionChannel::isSocketBusy() const | - | ||||||||||||||||||
| 720 | { | - | ||||||||||||||||||
| 721 | return (state & QHttpNetworkConnectionChannel::BusyState); executed 5417 times by 6 tests: return (state & QHttpNetworkConnectionChannel::BusyState);Executed by:
| 5417 | ||||||||||||||||||
| 722 | } | - | ||||||||||||||||||
| 723 | - | |||||||||||||||||||
| 724 | bool QHttpNetworkConnectionChannel::isSocketWriting() const | - | ||||||||||||||||||
| 725 | { | - | ||||||||||||||||||
| 726 | return (state & QHttpNetworkConnectionChannel::WritingState); executed 3024 times by 3 tests: return (state & QHttpNetworkConnectionChannel::WritingState);Executed by:
| 3024 | ||||||||||||||||||
| 727 | } | - | ||||||||||||||||||
| 728 | - | |||||||||||||||||||
| 729 | bool QHttpNetworkConnectionChannel::isSocketWaiting() const | - | ||||||||||||||||||
| 730 | { | - | ||||||||||||||||||
| 731 | return (state & QHttpNetworkConnectionChannel::WaitingState); executed 9678 times by 6 tests: return (state & QHttpNetworkConnectionChannel::WaitingState);Executed by:
| 9678 | ||||||||||||||||||
| 732 | } | - | ||||||||||||||||||
| 733 | - | |||||||||||||||||||
| 734 | bool QHttpNetworkConnectionChannel::isSocketReading() const | - | ||||||||||||||||||
| 735 | { | - | ||||||||||||||||||
| 736 | return (state & QHttpNetworkConnectionChannel::ReadingState); executed 8520 times by 5 tests: return (state & QHttpNetworkConnectionChannel::ReadingState);Executed by:
| 8520 | ||||||||||||||||||
| 737 | } | - | ||||||||||||||||||
| 738 | - | |||||||||||||||||||
| 739 | void QHttpNetworkConnectionChannel::_q_bytesWritten(qint64 bytes) | - | ||||||||||||||||||
| 740 | { | - | ||||||||||||||||||
| 741 | Q_UNUSED(bytes); | - | ||||||||||||||||||
| 742 | if (ssl) {
| 946-1901 | ||||||||||||||||||
| 743 | // In the SSL case we want to send data from encryptedBytesWritten signal since that one | - | ||||||||||||||||||
| 744 | // is the one going down to the actual network, not only into some SSL buffer. | - | ||||||||||||||||||
| 745 | return; executed 1901 times by 3 tests: return;Executed by:
| 1901 | ||||||||||||||||||
| 746 | } | - | ||||||||||||||||||
| 747 | - | |||||||||||||||||||
| 748 | // bytes have been written to the socket. write even more of them :) | - | ||||||||||||||||||
| 749 | if (isSocketWriting())
| 233-713 | ||||||||||||||||||
| 750 | sendRequest(); executed 233 times by 1 test: sendRequest();Executed by:
| 233 | ||||||||||||||||||
| 751 | // otherwise we do nothing | - | ||||||||||||||||||
| 752 | } executed 946 times by 2 tests: end of blockExecuted by:
| 946 | ||||||||||||||||||
| 753 | - | |||||||||||||||||||
| 754 | void QHttpNetworkConnectionChannel::_q_disconnected() | - | ||||||||||||||||||
| 755 | { | - | ||||||||||||||||||
| 756 | if (state == QHttpNetworkConnectionChannel::ClosingState) {
| 6-243 | ||||||||||||||||||
| 757 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 758 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 759 | return; executed 243 times by 4 tests: return;Executed by:
| 243 | ||||||||||||||||||
| 760 | } | - | ||||||||||||||||||
| 761 | - | |||||||||||||||||||
| 762 | // read the available data before closing (also done in _q_error for other codepaths) | - | ||||||||||||||||||
| 763 | if ((isSocketWaiting() || isSocketReading()) && socket->bytesAvailable()) {
| 0-6 | ||||||||||||||||||
| 764 | if (reply) {
| 0 | ||||||||||||||||||
| 765 | state = QHttpNetworkConnectionChannel::ReadingState; | - | ||||||||||||||||||
| 766 | _q_receiveReply(); | - | ||||||||||||||||||
| 767 | } never executed: end of block | 0 | ||||||||||||||||||
| 768 | } else if (state == QHttpNetworkConnectionChannel::IdleState && resendCurrent) { never executed: end of block
| 0-6 | ||||||||||||||||||
| 769 | // re-sending request because the socket was in ClosingState | - | ||||||||||||||||||
| 770 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 771 | } never executed: end of block | 0 | ||||||||||||||||||
| 772 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 773 | - | |||||||||||||||||||
| 774 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 775 | - | |||||||||||||||||||
| 776 | pendingEncrypt = false; | - | ||||||||||||||||||
| 777 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 778 | - | |||||||||||||||||||
| 779 | - | |||||||||||||||||||
| 780 | void QHttpNetworkConnectionChannel::_q_connected() | - | ||||||||||||||||||
| 781 | { | - | ||||||||||||||||||
| 782 | // For the Happy Eyeballs we need to check if this is the first channel to connect. | - | ||||||||||||||||||
| 783 | if (connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::HostLookupPending || connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv4or6) {
| 0-781 | ||||||||||||||||||
| 784 | if (connection->d_func()->delayedConnectionTimer.isActive())
| 4-120 | ||||||||||||||||||
| 785 | connection->d_func()->delayedConnectionTimer.stop(); executed 4 times by 2 tests: connection->d_func()->delayedConnectionTimer.stop();Executed by:
| 4 | ||||||||||||||||||
| 786 | if (networkLayerPreference == QAbstractSocket::IPv4Protocol)
| 0-124 | ||||||||||||||||||
| 787 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; executed 124 times by 2 tests: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4;Executed by:
| 124 | ||||||||||||||||||
| 788 | else if (networkLayerPreference == QAbstractSocket::IPv6Protocol)
| 0 | ||||||||||||||||||
| 789 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; never executed: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; | 0 | ||||||||||||||||||
| 790 | else { | - | ||||||||||||||||||
| 791 | if (socket->peerAddress().protocol() == QAbstractSocket::IPv4Protocol)
| 0 | ||||||||||||||||||
| 792 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; never executed: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; | 0 | ||||||||||||||||||
| 793 | else | - | ||||||||||||||||||
| 794 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; never executed: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; | 0 | ||||||||||||||||||
| 795 | } | - | ||||||||||||||||||
| 796 | connection->d_func()->networkLayerDetected(networkLayerPreference); | - | ||||||||||||||||||
| 797 | } else { executed 124 times by 2 tests: end of blockExecuted by:
| 124 | ||||||||||||||||||
| 798 | if (((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (networkLayerPreference != QAbstractSocket::IPv4Protocol))
| 0-656 | ||||||||||||||||||
| 799 | || ((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (networkLayerPreference != QAbstractSocket::IPv6Protocol))) {
| 0-656 | ||||||||||||||||||
| 800 | close(); | - | ||||||||||||||||||
| 801 | // This is the second connection so it has to be closed and we can schedule it for another request. | - | ||||||||||||||||||
| 802 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 803 | return; never executed: return; | 0 | ||||||||||||||||||
| 804 | } | - | ||||||||||||||||||
| 805 | //The connections networkLayerState had already been decided. | - | ||||||||||||||||||
| 806 | } executed 657 times by 7 tests: end of blockExecuted by:
| 657 | ||||||||||||||||||
| 807 | - | |||||||||||||||||||
| 808 | // improve performance since we get the request sent by the kernel ASAP | - | ||||||||||||||||||
| 809 | //socket->setSocketOption(QAbstractSocket::LowDelayOption, 1); | - | ||||||||||||||||||
| 810 | // We have this commented out now. It did not have the effect we wanted. If we want to | - | ||||||||||||||||||
| 811 | // do this properly, Qt has to combine multiple HTTP requests into one buffer | - | ||||||||||||||||||
| 812 | // and send this to the kernel in one syscall and then the kernel immediately sends | - | ||||||||||||||||||
| 813 | // it as one TCP packet because of TCP_NODELAY. | - | ||||||||||||||||||
| 814 | // However, this code is currently not in Qt, so we rely on the kernel combining | - | ||||||||||||||||||
| 815 | // the requests into one TCP packet. | - | ||||||||||||||||||
| 816 | - | |||||||||||||||||||
| 817 | // not sure yet if it helps, but it makes sense | - | ||||||||||||||||||
| 818 | socket->setSocketOption(QAbstractSocket::KeepAliveOption, 1); | - | ||||||||||||||||||
| 819 | - | |||||||||||||||||||
| 820 | pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown; | - | ||||||||||||||||||
| 821 | - | |||||||||||||||||||
| 822 | // ### FIXME: if the server closes the connection unexpectedly, we shouldn't send the same broken request again! | - | ||||||||||||||||||
| 823 | //channels[i].reconnectAttempts = 2; | - | ||||||||||||||||||
| 824 | if (ssl || pendingEncrypt) { // FIXME: Didn't work properly with pendingEncrypt only, we should refactor this into an EncrypingState
| 0-660 | ||||||||||||||||||
| 825 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 826 | if (connection->sslContext().isNull()) {
| 26-95 | ||||||||||||||||||
| 827 | // this socket is making the 1st handshake for this connection, | - | ||||||||||||||||||
| 828 | // we need to set the SSL context so new sockets can reuse it | - | ||||||||||||||||||
| 829 | QSharedPointer<QSslContext> socketSslContext = QSslSocketPrivate::sslContext(static_cast<QSslSocket*>(socket)); | - | ||||||||||||||||||
| 830 | if (!socketSslContext.isNull())
| 0-95 | ||||||||||||||||||
| 831 | connection->setSslContext(socketSslContext); executed 95 times by 3 tests: connection->setSslContext(socketSslContext);Executed by:
| 95 | ||||||||||||||||||
| 832 | } executed 95 times by 3 tests: end of blockExecuted by:
| 95 | ||||||||||||||||||
| 833 | #endif | - | ||||||||||||||||||
| 834 | } else { executed 121 times by 3 tests: end of blockExecuted by:
| 121 | ||||||||||||||||||
| 835 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 836 | if (!reply)
| 136-524 | ||||||||||||||||||
| 837 | connection->d_func()->dequeueRequest(socket); executed 524 times by 8 tests: connection->d_func()->dequeueRequest(socket);Executed by:
| 524 | ||||||||||||||||||
| 838 | if (reply)
| 2-658 | ||||||||||||||||||
| 839 | sendRequest(); executed 658 times by 8 tests: sendRequest();Executed by:
| 658 | ||||||||||||||||||
| 840 | } executed 660 times by 8 tests: end of blockExecuted by:
| 660 | ||||||||||||||||||
| 841 | } | - | ||||||||||||||||||
| 842 | - | |||||||||||||||||||
| 843 | - | |||||||||||||||||||
| 844 | void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socketError) | - | ||||||||||||||||||
| 845 | { | - | ||||||||||||||||||
| 846 | if (!socket)
| 0-199 | ||||||||||||||||||
| 847 | return; never executed: return; | 0 | ||||||||||||||||||
| 848 | QNetworkReply::NetworkError errorCode = QNetworkReply::UnknownNetworkError; | - | ||||||||||||||||||
| 849 | - | |||||||||||||||||||
| 850 | switch (socketError) { | - | ||||||||||||||||||
| 851 | case QAbstractSocket::HostNotFoundError: executed 2 times by 1 test: case QAbstractSocket::HostNotFoundError:Executed by:
| 2 | ||||||||||||||||||
| 852 | errorCode = QNetworkReply::HostNotFoundError; | - | ||||||||||||||||||
| 853 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||
| 854 | case QAbstractSocket::ConnectionRefusedError: executed 124 times by 2 tests: case QAbstractSocket::ConnectionRefusedError:Executed by:
| 124 | ||||||||||||||||||
| 855 | errorCode = QNetworkReply::ConnectionRefusedError; | - | ||||||||||||||||||
| 856 | break; executed 124 times by 2 tests: break;Executed by:
| 124 | ||||||||||||||||||
| 857 | case QAbstractSocket::RemoteHostClosedError: executed 53 times by 3 tests: case QAbstractSocket::RemoteHostClosedError:Executed by:
| 53 | ||||||||||||||||||
| 858 | // This error for SSL comes twice in a row, first from SSL layer ("The TLS/SSL connection has been closed") then from TCP layer. | - | ||||||||||||||||||
| 859 | // Depending on timing it can also come three times in a row (first time when we try to write into a closing QSslSocket). | - | ||||||||||||||||||
| 860 | // The reconnectAttempts handling catches the cases where we can re-send the request. | - | ||||||||||||||||||
| 861 | if (!reply && state == QHttpNetworkConnectionChannel::IdleState) {
| 8-36 | ||||||||||||||||||
| 862 | // Not actually an error, it is normal for Keep-Alive connections to close after some time if no request | - | ||||||||||||||||||
| 863 | // is sent on them. No need to error the other replies below. Just bail out here. | - | ||||||||||||||||||
| 864 | // The _q_disconnected will handle the possibly pipelined replies | - | ||||||||||||||||||
| 865 | return; executed 9 times by 2 tests: return;Executed by:
| 9 | ||||||||||||||||||
| 866 | } else if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) {
| 0-44 | ||||||||||||||||||
| 867 | // Try to reconnect/resend before sending an error. | - | ||||||||||||||||||
| 868 | // While "Reading" the _q_disconnected() will handle this. | - | ||||||||||||||||||
| 869 | if (reconnectAttempts-- > 0) {
| 6-33 | ||||||||||||||||||
| 870 | resendCurrentRequest(); | - | ||||||||||||||||||
| 871 | return; executed 33 times by 2 tests: return;Executed by:
| 33 | ||||||||||||||||||
| 872 | } else { | - | ||||||||||||||||||
| 873 | errorCode = QNetworkReply::RemoteHostClosedError; | - | ||||||||||||||||||
| 874 | } executed 6 times by 2 tests: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 875 | } else if (state == QHttpNetworkConnectionChannel::ReadingState) {
| 0-5 | ||||||||||||||||||
| 876 | if (!reply)
| 0-5 | ||||||||||||||||||
| 877 | break; never executed: break; | 0 | ||||||||||||||||||
| 878 | - | |||||||||||||||||||
| 879 | if (!reply->d_func()->expectContent()) {
| 0-5 | ||||||||||||||||||
| 880 | // No content expected, this is a valid way to have the connection closed by the server | - | ||||||||||||||||||
| 881 | // We need to invoke this asynchronously to make sure the state() of the socket is on QAbstractSocket::UnconnectedState | - | ||||||||||||||||||
| 882 | QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection); | - | ||||||||||||||||||
| 883 | return; never executed: return; | 0 | ||||||||||||||||||
| 884 | } | - | ||||||||||||||||||
| 885 | if (reply->contentLength() == -1 && !reply->d_func()->isChunked()) {
| 0-5 | ||||||||||||||||||
| 886 | // There was no content-length header and it's not chunked encoding, | - | ||||||||||||||||||
| 887 | // so this is a valid way to have the connection closed by the server | - | ||||||||||||||||||
| 888 | // We need to invoke this asynchronously to make sure the state() of the socket is on QAbstractSocket::UnconnectedState | - | ||||||||||||||||||
| 889 | QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection); | - | ||||||||||||||||||
| 890 | return; executed 5 times by 1 test: return;Executed by:
| 5 | ||||||||||||||||||
| 891 | } | - | ||||||||||||||||||
| 892 | // ok, we got a disconnect even though we did not expect it | - | ||||||||||||||||||
| 893 | // Try to read everything from the socket before we emit the error. | - | ||||||||||||||||||
| 894 | if (socket->bytesAvailable()) {
| 0 | ||||||||||||||||||
| 895 | // Read everything from the socket into the reply buffer. | - | ||||||||||||||||||
| 896 | // we can ignore the readbuffersize as the data is already | - | ||||||||||||||||||
| 897 | // in memory and we will not receive more data on the socket. | - | ||||||||||||||||||
| 898 | reply->setReadBufferSize(0); | - | ||||||||||||||||||
| 899 | reply->setDownstreamLimited(false); | - | ||||||||||||||||||
| 900 | _q_receiveReply(); | - | ||||||||||||||||||
| 901 | if (!reply) {
| 0 | ||||||||||||||||||
| 902 | // No more reply assigned after the previous call? Then it had been finished successfully. | - | ||||||||||||||||||
| 903 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 904 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 905 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 906 | return; never executed: return; | 0 | ||||||||||||||||||
| 907 | } | - | ||||||||||||||||||
| 908 | } never executed: end of block | 0 | ||||||||||||||||||
| 909 | - | |||||||||||||||||||
| 910 | errorCode = QNetworkReply::RemoteHostClosedError; | - | ||||||||||||||||||
| 911 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 912 | errorCode = QNetworkReply::RemoteHostClosedError; | - | ||||||||||||||||||
| 913 | } never executed: end of block | 0 | ||||||||||||||||||
| 914 | break; executed 6 times by 2 tests: break;Executed by:
| 6 | ||||||||||||||||||
| 915 | case QAbstractSocket::SocketTimeoutError: never executed: case QAbstractSocket::SocketTimeoutError: | 0 | ||||||||||||||||||
| 916 | // try to reconnect/resend before sending an error. | - | ||||||||||||||||||
| 917 | if (state == QHttpNetworkConnectionChannel::WritingState && (reconnectAttempts-- > 0)) {
| 0 | ||||||||||||||||||
| 918 | resendCurrentRequest(); | - | ||||||||||||||||||
| 919 | return; never executed: return; | 0 | ||||||||||||||||||
| 920 | } | - | ||||||||||||||||||
| 921 | errorCode = QNetworkReply::TimeoutError; | - | ||||||||||||||||||
| 922 | break; never executed: break; | 0 | ||||||||||||||||||
| 923 | case QAbstractSocket::ProxyAuthenticationRequiredError: executed 5 times by 2 tests: case QAbstractSocket::ProxyAuthenticationRequiredError:Executed by:
| 5 | ||||||||||||||||||
| 924 | errorCode = QNetworkReply::ProxyAuthenticationRequiredError; | - | ||||||||||||||||||
| 925 | break; executed 5 times by 2 tests: break;Executed by:
| 5 | ||||||||||||||||||
| 926 | case QAbstractSocket::SslHandshakeFailedError: executed 12 times by 3 tests: case QAbstractSocket::SslHandshakeFailedError:Executed by:
| 12 | ||||||||||||||||||
| 927 | errorCode = QNetworkReply::SslHandshakeFailedError; | - | ||||||||||||||||||
| 928 | break; executed 12 times by 3 tests: break;Executed by:
| 12 | ||||||||||||||||||
| 929 | case QAbstractSocket::ProxyConnectionClosedError: never executed: case QAbstractSocket::ProxyConnectionClosedError: | 0 | ||||||||||||||||||
| 930 | // try to reconnect/resend before sending an error. | - | ||||||||||||||||||
| 931 | if (reconnectAttempts-- > 0) {
| 0 | ||||||||||||||||||
| 932 | resendCurrentRequest(); | - | ||||||||||||||||||
| 933 | return; never executed: return; | 0 | ||||||||||||||||||
| 934 | } | - | ||||||||||||||||||
| 935 | errorCode = QNetworkReply::ProxyConnectionClosedError; | - | ||||||||||||||||||
| 936 | break; never executed: break; | 0 | ||||||||||||||||||
| 937 | case QAbstractSocket::ProxyConnectionTimeoutError: never executed: case QAbstractSocket::ProxyConnectionTimeoutError: | 0 | ||||||||||||||||||
| 938 | // try to reconnect/resend before sending an error. | - | ||||||||||||||||||
| 939 | if (reconnectAttempts-- > 0) {
| 0 | ||||||||||||||||||
| 940 | resendCurrentRequest(); | - | ||||||||||||||||||
| 941 | return; never executed: return; | 0 | ||||||||||||||||||
| 942 | } | - | ||||||||||||||||||
| 943 | errorCode = QNetworkReply::ProxyTimeoutError; | - | ||||||||||||||||||
| 944 | break; never executed: break; | 0 | ||||||||||||||||||
| 945 | default: executed 3 times by 2 tests: default:Executed by:
| 3 | ||||||||||||||||||
| 946 | // all other errors are treated as NetworkError | - | ||||||||||||||||||
| 947 | errorCode = QNetworkReply::UnknownNetworkError; | - | ||||||||||||||||||
| 948 | break; executed 3 times by 2 tests: break;Executed by:
| 3 | ||||||||||||||||||
| 949 | } | - | ||||||||||||||||||
| 950 | QPointer<QHttpNetworkConnection> that = connection; | - | ||||||||||||||||||
| 951 | QString errorString = connection->d_func()->errorDetail(errorCode, socket, socket->errorString()); | - | ||||||||||||||||||
| 952 | - | |||||||||||||||||||
| 953 | // In the HostLookupPending state the channel should not emit the error. | - | ||||||||||||||||||
| 954 | // This will instead be handled by the connection. | - | ||||||||||||||||||
| 955 | if (!connection->d_func()->shouldEmitChannelError(socket))
| 30-122 | ||||||||||||||||||
| 956 | return; executed 122 times by 2 tests: return;Executed by:
| 122 | ||||||||||||||||||
| 957 | - | |||||||||||||||||||
| 958 | // emit error for all waiting replies | - | ||||||||||||||||||
| 959 | do { | - | ||||||||||||||||||
| 960 | // Need to dequeu the request so that we can emit the error. | - | ||||||||||||||||||
| 961 | if (!reply)
| 12-20 | ||||||||||||||||||
| 962 | connection->d_func()->dequeueRequest(socket); executed 12 times by 3 tests: connection->d_func()->dequeueRequest(socket);Executed by:
| 12 | ||||||||||||||||||
| 963 | - | |||||||||||||||||||
| 964 | if (reply) {
| 3-29 | ||||||||||||||||||
| 965 | reply->d_func()->errorString = errorString; | - | ||||||||||||||||||
| 966 | emit reply->finishedWithError(errorCode, errorString); | - | ||||||||||||||||||
| 967 | reply = 0; | - | ||||||||||||||||||
| 968 | if (protocolHandler)
| 12-17 | ||||||||||||||||||
| 969 | protocolHandler->setReply(0); executed 12 times by 3 tests: protocolHandler->setReply(0);Executed by:
| 12 | ||||||||||||||||||
| 970 | } executed 29 times by 3 tests: end of blockExecuted by:
| 29 | ||||||||||||||||||
| 971 | } while (!connection->d_func()->highPriorityQueue.isEmpty() executed 32 times by 4 tests: end of blockExecuted by:
| 0-32 | ||||||||||||||||||
| 972 | || !connection->d_func()->lowPriorityQueue.isEmpty());
| 2-30 | ||||||||||||||||||
| 973 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 974 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY) {
| 3-27 | ||||||||||||||||||
| 975 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
| 976 | for (int a = 0; a < spdyPairs.count(); ++a) {
| 3 | ||||||||||||||||||
| 977 | // emit error for all replies | - | ||||||||||||||||||
| 978 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
| 979 | Q_ASSERT(currentReply); | - | ||||||||||||||||||
| 980 | emit currentReply->finishedWithError(errorCode, errorString); | - | ||||||||||||||||||
| 981 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 982 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 983 | #endif // QT_NO_SSL | - | ||||||||||||||||||
| 984 | - | |||||||||||||||||||
| 985 | // send the next request | - | ||||||||||||||||||
| 986 | QMetaObject::invokeMethod(that, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 987 | - | |||||||||||||||||||
| 988 | if (that) {
| 0-30 | ||||||||||||||||||
| 989 | //signal emission triggered event loop | - | ||||||||||||||||||
| 990 | if (!socket)
| 0-30 | ||||||||||||||||||
| 991 | state = QHttpNetworkConnectionChannel::IdleState; never executed: state = QHttpNetworkConnectionChannel::IdleState; | 0 | ||||||||||||||||||
| 992 | else if (socket->state() == QAbstractSocket::UnconnectedState)
| 13-17 | ||||||||||||||||||
| 993 | state = QHttpNetworkConnectionChannel::IdleState; executed 17 times by 4 tests: state = QHttpNetworkConnectionChannel::IdleState;Executed by:
| 17 | ||||||||||||||||||
| 994 | else | - | ||||||||||||||||||
| 995 | state = QHttpNetworkConnectionChannel::ClosingState; executed 13 times by 2 tests: state = QHttpNetworkConnectionChannel::ClosingState;Executed by:
| 13 | ||||||||||||||||||
| 996 | - | |||||||||||||||||||
| 997 | // pendingEncrypt must only be true in between connected and encrypted states | - | ||||||||||||||||||
| 998 | pendingEncrypt = false; | - | ||||||||||||||||||
| 999 | } executed 30 times by 4 tests: end of blockExecuted by:
| 30 | ||||||||||||||||||
| 1000 | } executed 30 times by 4 tests: end of blockExecuted by:
| 30 | ||||||||||||||||||
| 1001 | - | |||||||||||||||||||
| 1002 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 1003 | void QHttpNetworkConnectionChannel::_q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator* auth) | - | ||||||||||||||||||
| 1004 | { | - | ||||||||||||||||||
| 1005 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1006 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY) {
| 3-39 | ||||||||||||||||||
| 1007 | connection->d_func()->emitProxyAuthenticationRequired(this, proxy, auth); | - | ||||||||||||||||||
| 1008 | } else { // HTTP executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 1009 | #endif // QT_NO_SSL | - | ||||||||||||||||||
| 1010 | // Need to dequeue the request before we can emit the error. | - | ||||||||||||||||||
| 1011 | if (!reply)
| 2-37 | ||||||||||||||||||
| 1012 | connection->d_func()->dequeueRequest(socket); executed 37 times by 1 test: connection->d_func()->dequeueRequest(socket);Executed by:
| 37 | ||||||||||||||||||
| 1013 | if (reply)
| 0-39 | ||||||||||||||||||
| 1014 | connection->d_func()->emitProxyAuthenticationRequired(this, proxy, auth); executed 39 times by 1 test: connection->d_func()->emitProxyAuthenticationRequired(this, proxy, auth);Executed by:
| 39 | ||||||||||||||||||
| 1015 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1016 | } executed 39 times by 1 test: end of blockExecuted by:
| 39 | ||||||||||||||||||
| 1017 | #endif // QT_NO_SSL | - | ||||||||||||||||||
| 1018 | } | - | ||||||||||||||||||
| 1019 | #endif | - | ||||||||||||||||||
| 1020 | - | |||||||||||||||||||
| 1021 | void QHttpNetworkConnectionChannel::_q_uploadDataReadyRead() | - | ||||||||||||||||||
| 1022 | { | - | ||||||||||||||||||
| 1023 | if (reply)
| 0-1964 | ||||||||||||||||||
| 1024 | sendRequest(); executed 1964 times by 2 tests: sendRequest();Executed by:
| 1964 | ||||||||||||||||||
| 1025 | } executed 1964 times by 2 tests: end of blockExecuted by:
| 1964 | ||||||||||||||||||
| 1026 | - | |||||||||||||||||||
| 1027 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1028 | void QHttpNetworkConnectionChannel::_q_encrypted() | - | ||||||||||||||||||
| 1029 | { | - | ||||||||||||||||||
| 1030 | QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket); | - | ||||||||||||||||||
| 1031 | Q_ASSERT(sslSocket); | - | ||||||||||||||||||
| 1032 | - | |||||||||||||||||||
| 1033 | if (!protocolHandler) {
| 10-91 | ||||||||||||||||||
| 1034 | switch (sslSocket->sslConfiguration().nextProtocolNegotiationStatus()) { | - | ||||||||||||||||||
| 1035 | case QSslConfiguration::NextProtocolNegotiationNegotiated: /* fall through */ executed 6 times by 1 test: case QSslConfiguration::NextProtocolNegotiationNegotiated:Executed by:
| 6 | ||||||||||||||||||
| 1036 | case QSslConfiguration::NextProtocolNegotiationUnsupported: { never executed: case QSslConfiguration::NextProtocolNegotiationUnsupported: | 0 | ||||||||||||||||||
| 1037 | QByteArray nextProtocol = sslSocket->sslConfiguration().nextNegotiatedProtocol(); | - | ||||||||||||||||||
| 1038 | if (nextProtocol == QSslConfiguration::NextProtocolHttp1_1) {
| 0-6 | ||||||||||||||||||
| 1039 | // fall through to create a QHttpProtocolHandler | - | ||||||||||||||||||
| 1040 | } else if (nextProtocol == QSslConfiguration::NextProtocolSpdy3_0) { never executed: end of block
| 0-6 | ||||||||||||||||||
| 1041 | protocolHandler.reset(new QSpdyProtocolHandler(this)); | - | ||||||||||||||||||
| 1042 | connection->setConnectionType(QHttpNetworkConnection::ConnectionTypeSPDY); | - | ||||||||||||||||||
| 1043 | // no need to re-queue requests, if SPDY was enabled on the request it | - | ||||||||||||||||||
| 1044 | // has gone to the SPDY queue already | - | ||||||||||||||||||
| 1045 | break; executed 6 times by 1 test: break;Executed by:
| 6 | ||||||||||||||||||
| 1046 | } else { | - | ||||||||||||||||||
| 1047 | emitFinishedWithError(QNetworkReply::SslHandshakeFailedError, | - | ||||||||||||||||||
| 1048 | "detected unknown Next Protocol Negotiation protocol"); | - | ||||||||||||||||||
| 1049 | break; never executed: break; | 0 | ||||||||||||||||||
| 1050 | } | - | ||||||||||||||||||
| 1051 | } | - | ||||||||||||||||||
| 1052 | case QSslConfiguration::NextProtocolNegotiationNone: code before this statement never executed: case QSslConfiguration::NextProtocolNegotiationNone:executed 85 times by 3 tests: case QSslConfiguration::NextProtocolNegotiationNone:Executed by:
| 0-85 | ||||||||||||||||||
| 1053 | protocolHandler.reset(new QHttpProtocolHandler(this)); | - | ||||||||||||||||||
| 1054 | connection->setConnectionType(QHttpNetworkConnection::ConnectionTypeHTTP); | - | ||||||||||||||||||
| 1055 | // re-queue requests from SPDY queue to HTTP queue, if any | - | ||||||||||||||||||
| 1056 | requeueSpdyRequests(); | - | ||||||||||||||||||
| 1057 | break; executed 85 times by 3 tests: break;Executed by:
| 85 | ||||||||||||||||||
| 1058 | default: never executed: default: | 0 | ||||||||||||||||||
| 1059 | emitFinishedWithError(QNetworkReply::SslHandshakeFailedError, | - | ||||||||||||||||||
| 1060 | "detected unknown Next Protocol Negotiation protocol"); | - | ||||||||||||||||||
| 1061 | } never executed: end of block | 0 | ||||||||||||||||||
| 1062 | } | - | ||||||||||||||||||
| 1063 | - | |||||||||||||||||||
| 1064 | if (!socket)
| 0-101 | ||||||||||||||||||
| 1065 | return; // ### error never executed: return; | 0 | ||||||||||||||||||
| 1066 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 1067 | pendingEncrypt = false; | - | ||||||||||||||||||
| 1068 | - | |||||||||||||||||||
| 1069 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY) {
| 6-95 | ||||||||||||||||||
| 1070 | // we call setSpdyWasUsed(true) on the replies in the SPDY handler when the request is sent | - | ||||||||||||||||||
| 1071 | if (spdyRequestsToSend.count() > 0)
| 0-6 | ||||||||||||||||||
| 1072 | // wait for data from the server first (e.g. initial window, max concurrent requests) | - | ||||||||||||||||||
| 1073 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 6 times by 1 test: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);Executed by:
| 6 | ||||||||||||||||||
| 1074 | } else { // HTTP executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 1075 | if (!reply)
| 39-56 | ||||||||||||||||||
| 1076 | connection->d_func()->dequeueRequest(socket); executed 56 times by 1 test: connection->d_func()->dequeueRequest(socket);Executed by:
| 56 | ||||||||||||||||||
| 1077 | if (reply) {
| 3-92 | ||||||||||||||||||
| 1078 | reply->setSpdyWasUsed(false); | - | ||||||||||||||||||
| 1079 | Q_ASSERT(reply->d_func()->connectionChannel == this); | - | ||||||||||||||||||
| 1080 | emit reply->encrypted(); | - | ||||||||||||||||||
| 1081 | } executed 92 times by 3 tests: end of blockExecuted by:
| 92 | ||||||||||||||||||
| 1082 | if (reply)
| 3-92 | ||||||||||||||||||
| 1083 | sendRequest(); executed 92 times by 3 tests: sendRequest();Executed by:
| 92 | ||||||||||||||||||
| 1084 | } executed 95 times by 3 tests: end of blockExecuted by:
| 95 | ||||||||||||||||||
| 1085 | } | - | ||||||||||||||||||
| 1086 | - | |||||||||||||||||||
| 1087 | void QHttpNetworkConnectionChannel::requeueSpdyRequests() | - | ||||||||||||||||||
| 1088 | { | - | ||||||||||||||||||
| 1089 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
| 1090 | for (int a = 0; a < spdyPairs.count(); ++a) {
| 0-85 | ||||||||||||||||||
| 1091 | connection->d_func()->requeueRequest(spdyPairs.at(a)); | - | ||||||||||||||||||
| 1092 | } never executed: end of block | 0 | ||||||||||||||||||
| 1093 | spdyRequestsToSend.clear(); | - | ||||||||||||||||||
| 1094 | } executed 85 times by 3 tests: end of blockExecuted by:
| 85 | ||||||||||||||||||
| 1095 | - | |||||||||||||||||||
| 1096 | void QHttpNetworkConnectionChannel::emitFinishedWithError(QNetworkReply::NetworkError error, | - | ||||||||||||||||||
| 1097 | const char *message) | - | ||||||||||||||||||
| 1098 | { | - | ||||||||||||||||||
| 1099 | if (reply)
| 0 | ||||||||||||||||||
| 1100 | emit reply->finishedWithError(error, QHttpNetworkConnectionChannel::tr(message)); never executed: reply->finishedWithError(error, QHttpNetworkConnectionChannel::tr(message)); | 0 | ||||||||||||||||||
| 1101 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
| 1102 | for (int a = 0; a < spdyPairs.count(); ++a) {
| 0 | ||||||||||||||||||
| 1103 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
| 1104 | Q_ASSERT(currentReply); | - | ||||||||||||||||||
| 1105 | emit currentReply->finishedWithError(error, QHttpNetworkConnectionChannel::tr(message)); | - | ||||||||||||||||||
| 1106 | } never executed: end of block | 0 | ||||||||||||||||||
| 1107 | } never executed: end of block | 0 | ||||||||||||||||||
| 1108 | - | |||||||||||||||||||
| 1109 | void QHttpNetworkConnectionChannel::_q_sslErrors(const QList<QSslError> &errors) | - | ||||||||||||||||||
| 1110 | { | - | ||||||||||||||||||
| 1111 | if (!socket)
| 0-54 | ||||||||||||||||||
| 1112 | return; never executed: return; | 0 | ||||||||||||||||||
| 1113 | //QNetworkReply::NetworkError errorCode = QNetworkReply::ProtocolFailure; | - | ||||||||||||||||||
| 1114 | // Also pause the connection because socket notifiers may fire while an user | - | ||||||||||||||||||
| 1115 | // dialog is displaying | - | ||||||||||||||||||
| 1116 | connection->d_func()->pauseConnection(); | - | ||||||||||||||||||
| 1117 | if (pendingEncrypt && !reply)
| 0-54 | ||||||||||||||||||
| 1118 | connection->d_func()->dequeueRequest(socket); executed 48 times by 3 tests: connection->d_func()->dequeueRequest(socket);Executed by:
| 48 | ||||||||||||||||||
| 1119 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP) {
| 7-47 | ||||||||||||||||||
| 1120 | if (reply)
| 2-45 | ||||||||||||||||||
| 1121 | emit reply->sslErrors(errors); executed 45 times by 3 tests: reply->sslErrors(errors);Executed by:
| 45 | ||||||||||||||||||
| 1122 | } executed 47 times by 3 tests: end of blockExecuted by:
| 47 | ||||||||||||||||||
| 1123 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1124 | else { // SPDY | - | ||||||||||||||||||
| 1125 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
| 1126 | for (int a = 0; a < spdyPairs.count(); ++a) {
| 7 | ||||||||||||||||||
| 1127 | // emit SSL errors for all replies | - | ||||||||||||||||||
| 1128 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
| 1129 | Q_ASSERT(currentReply); | - | ||||||||||||||||||
| 1130 | emit currentReply->sslErrors(errors); | - | ||||||||||||||||||
| 1131 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||
| 1132 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||
| 1133 | #endif // QT_NO_SSL | - | ||||||||||||||||||
| 1134 | connection->d_func()->resumeConnection(); | - | ||||||||||||||||||
| 1135 | } executed 54 times by 3 tests: end of blockExecuted by:
| 54 | ||||||||||||||||||
| 1136 | - | |||||||||||||||||||
| 1137 | void QHttpNetworkConnectionChannel::_q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator) | - | ||||||||||||||||||
| 1138 | { | - | ||||||||||||||||||
| 1139 | connection->d_func()->pauseConnection(); | - | ||||||||||||||||||
| 1140 | - | |||||||||||||||||||
| 1141 | if (pendingEncrypt && !reply)
| 0 | ||||||||||||||||||
| 1142 | connection->d_func()->dequeueRequest(socket); never executed: connection->d_func()->dequeueRequest(socket); | 0 | ||||||||||||||||||
| 1143 | - | |||||||||||||||||||
| 1144 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP) {
| 0 | ||||||||||||||||||
| 1145 | if (reply)
| 0 | ||||||||||||||||||
| 1146 | emit reply->preSharedKeyAuthenticationRequired(authenticator); never executed: reply->preSharedKeyAuthenticationRequired(authenticator); | 0 | ||||||||||||||||||
| 1147 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1148 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
| 1149 | for (int a = 0; a < spdyPairs.count(); ++a) {
| 0 | ||||||||||||||||||
| 1150 | // emit SSL errors for all replies | - | ||||||||||||||||||
| 1151 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
| 1152 | Q_ASSERT(currentReply); | - | ||||||||||||||||||
| 1153 | emit currentReply->preSharedKeyAuthenticationRequired(authenticator); | - | ||||||||||||||||||
| 1154 | } never executed: end of block | 0 | ||||||||||||||||||
| 1155 | } never executed: end of block | 0 | ||||||||||||||||||
| 1156 | - | |||||||||||||||||||
| 1157 | connection->d_func()->resumeConnection(); | - | ||||||||||||||||||
| 1158 | } never executed: end of block | 0 | ||||||||||||||||||
| 1159 | - | |||||||||||||||||||
| 1160 | void QHttpNetworkConnectionChannel::_q_encryptedBytesWritten(qint64 bytes) | - | ||||||||||||||||||
| 1161 | { | - | ||||||||||||||||||
| 1162 | Q_UNUSED(bytes); | - | ||||||||||||||||||
| 1163 | // bytes have been written to the socket. write even more of them :) | - | ||||||||||||||||||
| 1164 | if (isSocketWriting())
| 896-1182 | ||||||||||||||||||
| 1165 | sendRequest(); executed 896 times by 1 test: sendRequest();Executed by:
| 896 | ||||||||||||||||||
| 1166 | // otherwise we do nothing | - | ||||||||||||||||||
| 1167 | } executed 2078 times by 3 tests: end of blockExecuted by:
| 2078 | ||||||||||||||||||
| 1168 | - | |||||||||||||||||||
| 1169 | #endif | - | ||||||||||||||||||
| 1170 | - | |||||||||||||||||||
| 1171 | void QHttpNetworkConnectionChannel::setConnection(QHttpNetworkConnection *c) | - | ||||||||||||||||||
| 1172 | { | - | ||||||||||||||||||
| 1173 | // Inlining this function in the header leads to compiler error on | - | ||||||||||||||||||
| 1174 | // release-armv5, on at least timebox 9.2 and 10.1. | - | ||||||||||||||||||
| 1175 | connection = c; | - | ||||||||||||||||||
| 1176 | } executed 3416 times by 8 tests: end of blockExecuted by:
| 3416 | ||||||||||||||||||
| 1177 | - | |||||||||||||||||||
| 1178 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 1179 | - | |||||||||||||||||||
| 1180 | #include "moc_qhttpnetworkconnectionchannel_p.cpp" | - | ||||||||||||||||||
| 1181 | - | |||||||||||||||||||
| 1182 | #endif // QT_NO_HTTP | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |