| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qhttpnetworkconnection.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qhttpnetworkconnection_p.h" | - | ||||||||||||||||||
| 41 | #include <private/qabstractsocket_p.h> | - | ||||||||||||||||||
| 42 | #include "qhttpnetworkconnectionchannel_p.h" | - | ||||||||||||||||||
| 43 | #include "private/qnoncontiguousbytedevice_p.h" | - | ||||||||||||||||||
| 44 | #include <private/qnetworkrequest_p.h> | - | ||||||||||||||||||
| 45 | #include <private/qobject_p.h> | - | ||||||||||||||||||
| 46 | #include <private/qauthenticator_p.h> | - | ||||||||||||||||||
| 47 | #include "private/qhostinfo_p.h" | - | ||||||||||||||||||
| 48 | #include <qnetworkproxy.h> | - | ||||||||||||||||||
| 49 | #include <qauthenticator.h> | - | ||||||||||||||||||
| 50 | #include <qcoreapplication.h> | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | #include <qbuffer.h> | - | ||||||||||||||||||
| 53 | #include <qpair.h> | - | ||||||||||||||||||
| 54 | #include <qdebug.h> | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | #ifndef QT_NO_HTTP | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 59 | # include <private/qsslsocket_p.h> | - | ||||||||||||||||||
| 60 | # include <QtNetwork/qsslkey.h> | - | ||||||||||||||||||
| 61 | # include <QtNetwork/qsslcipher.h> | - | ||||||||||||||||||
| 62 | # include <QtNetwork/qsslconfiguration.h> | - | ||||||||||||||||||
| 63 | #endif | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | const int QHttpNetworkConnectionPrivate::defaultHttpChannelCount = 6; | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | // The pipeline length. So there will be 4 requests in flight. | - | ||||||||||||||||||
| 72 | const int QHttpNetworkConnectionPrivate::defaultPipelineLength = 3; | - | ||||||||||||||||||
| 73 | // Only re-fill the pipeline if there's defaultRePipelineLength slots free in the pipeline. | - | ||||||||||||||||||
| 74 | // This means that there are 2 requests in flight and 2 slots free that will be re-filled. | - | ||||||||||||||||||
| 75 | const int QHttpNetworkConnectionPrivate::defaultRePipelineLength = 2; | - | ||||||||||||||||||
| 76 | - | |||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &hostName, | - | ||||||||||||||||||
| 79 | quint16 port, bool encrypt, | - | ||||||||||||||||||
| 80 | QHttpNetworkConnection::ConnectionType type) | - | ||||||||||||||||||
| 81 | : state(RunningState), | - | ||||||||||||||||||
| 82 | networkLayerState(Unknown), | - | ||||||||||||||||||
| 83 | hostName(hostName), port(port), encrypt(encrypt), delayIpv4(true) | - | ||||||||||||||||||
| 84 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 85 | , channelCount((type == QHttpNetworkConnection::ConnectionTypeSPDY) ? 1 : defaultHttpChannelCount) | - | ||||||||||||||||||
| 86 | #else | - | ||||||||||||||||||
| 87 | , channelCount(defaultHttpChannelCount) | - | ||||||||||||||||||
| 88 | #endif // QT_NO_SSL | - | ||||||||||||||||||
| 89 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 90 | , networkProxy(QNetworkProxy::NoProxy) | - | ||||||||||||||||||
| 91 | #endif | - | ||||||||||||||||||
| 92 | , preConnectRequests(0) | - | ||||||||||||||||||
| 93 | , connectionType(type) | - | ||||||||||||||||||
| 94 | { | - | ||||||||||||||||||
| 95 | channels = new QHttpNetworkConnectionChannel[channelCount]; | - | ||||||||||||||||||
| 96 | } executed 575 times by 8 tests: end of blockExecuted by:
| 575 | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(quint16 channelCount, const QString &hostName, | - | ||||||||||||||||||
| 99 | quint16 port, bool encrypt, | - | ||||||||||||||||||
| 100 | QHttpNetworkConnection::ConnectionType type) | - | ||||||||||||||||||
| 101 | : state(RunningState), networkLayerState(Unknown), | - | ||||||||||||||||||
| 102 | hostName(hostName), port(port), encrypt(encrypt), delayIpv4(true), | - | ||||||||||||||||||
| 103 | channelCount(channelCount) | - | ||||||||||||||||||
| 104 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 105 | , networkProxy(QNetworkProxy::NoProxy) | - | ||||||||||||||||||
| 106 | #endif | - | ||||||||||||||||||
| 107 | , preConnectRequests(0) | - | ||||||||||||||||||
| 108 | , connectionType(type) | - | ||||||||||||||||||
| 109 | { | - | ||||||||||||||||||
| 110 | channels = new QHttpNetworkConnectionChannel[channelCount]; | - | ||||||||||||||||||
| 111 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | QHttpNetworkConnectionPrivate::~QHttpNetworkConnectionPrivate() | - | ||||||||||||||||||
| 116 | { | - | ||||||||||||||||||
| 117 | for (int i = 0; i < channelCount; ++i) {
| 582-3410 | ||||||||||||||||||
| 118 | if (channels[i].socket) {
| 752-2658 | ||||||||||||||||||
| 119 | QObject::disconnect(channels[i].socket, Q_NULLPTR, &channels[i], Q_NULLPTR); | - | ||||||||||||||||||
| 120 | channels[i].socket->close(); | - | ||||||||||||||||||
| 121 | delete channels[i].socket; | - | ||||||||||||||||||
| 122 | } executed 752 times by 9 tests: end of blockExecuted by:
| 752 | ||||||||||||||||||
| 123 | } executed 3410 times by 9 tests: end of blockExecuted by:
| 3410 | ||||||||||||||||||
| 124 | delete []channels; | - | ||||||||||||||||||
| 125 | } executed 582 times by 9 tests: end of blockExecuted by:
| 582 | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | void QHttpNetworkConnectionPrivate::init() | - | ||||||||||||||||||
| 128 | { | - | ||||||||||||||||||
| 129 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
| 130 | for (int i = 0; i < channelCount; i++) {
| 583-3416 | ||||||||||||||||||
| 131 | channels[i].setConnection(this->q_func()); | - | ||||||||||||||||||
| 132 | channels[i].ssl = encrypt; | - | ||||||||||||||||||
| 133 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 134 | //push session down to channels | - | ||||||||||||||||||
| 135 | channels[i].networkSession = networkSession; | - | ||||||||||||||||||
| 136 | #endif | - | ||||||||||||||||||
| 137 | } executed 3416 times by 8 tests: end of blockExecuted by:
| 3416 | ||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | delayedConnectionTimer.setSingleShot(true); | - | ||||||||||||||||||
| 140 | QObject::connect(&delayedConnectionTimer, SIGNAL(timeout()), q, SLOT(_q_connectDelayedChannel())); | - | ||||||||||||||||||
| 141 | } executed 583 times by 8 tests: end of blockExecuted by:
| 583 | ||||||||||||||||||
| 142 | - | |||||||||||||||||||
| 143 | void QHttpNetworkConnectionPrivate::pauseConnection() | - | ||||||||||||||||||
| 144 | { | - | ||||||||||||||||||
| 145 | state = PausedState; | - | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | // Disable all socket notifiers | - | ||||||||||||||||||
| 148 | for (int i = 0; i < channelCount; i++) {
| 275-1600 | ||||||||||||||||||
| 149 | if (channels[i].socket) {
| 325-1275 | ||||||||||||||||||
| 150 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 151 | if (encrypt)
| 128-197 | ||||||||||||||||||
| 152 | QSslSocketPrivate::pauseSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket)); executed 128 times by 3 tests: QSslSocketPrivate::pauseSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket));Executed by:
| 128 | ||||||||||||||||||
| 153 | else | - | ||||||||||||||||||
| 154 | #endif | - | ||||||||||||||||||
| 155 | QAbstractSocketPrivate::pauseSocketNotifiers(channels[i].socket); executed 197 times by 2 tests: QAbstractSocketPrivate::pauseSocketNotifiers(channels[i].socket);Executed by:
| 197 | ||||||||||||||||||
| 156 | } | - | ||||||||||||||||||
| 157 | } executed 1600 times by 3 tests: end of blockExecuted by:
| 1600 | ||||||||||||||||||
| 158 | } executed 275 times by 3 tests: end of blockExecuted by:
| 275 | ||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | void QHttpNetworkConnectionPrivate::resumeConnection() | - | ||||||||||||||||||
| 161 | { | - | ||||||||||||||||||
| 162 | state = RunningState; | - | ||||||||||||||||||
| 163 | // Enable all socket notifiers | - | ||||||||||||||||||
| 164 | for (int i = 0; i < channelCount; i++) {
| 275-1600 | ||||||||||||||||||
| 165 | if (channels[i].socket) {
| 325-1275 | ||||||||||||||||||
| 166 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 167 | if (encrypt)
| 128-197 | ||||||||||||||||||
| 168 | QSslSocketPrivate::resumeSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket)); executed 128 times by 3 tests: QSslSocketPrivate::resumeSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket));Executed by:
| 128 | ||||||||||||||||||
| 169 | else | - | ||||||||||||||||||
| 170 | #endif | - | ||||||||||||||||||
| 171 | QAbstractSocketPrivate::resumeSocketNotifiers(channels[i].socket); executed 197 times by 2 tests: QAbstractSocketPrivate::resumeSocketNotifiers(channels[i].socket);Executed by:
| 197 | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | // Resume pending upload if needed | - | ||||||||||||||||||
| 174 | if (channels[i].state == QHttpNetworkConnectionChannel::WritingState)
| 0-325 | ||||||||||||||||||
| 175 | QMetaObject::invokeMethod(&channels[i], "_q_uploadDataReadyRead", Qt::QueuedConnection); never executed: QMetaObject::invokeMethod(&channels[i], "_q_uploadDataReadyRead", Qt::QueuedConnection); | 0 | ||||||||||||||||||
| 176 | } executed 325 times by 3 tests: end of blockExecuted by:
| 325 | ||||||||||||||||||
| 177 | } executed 1600 times by 3 tests: end of blockExecuted by:
| 1600 | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | // queue _q_startNextRequest | - | ||||||||||||||||||
| 180 | QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 181 | } executed 275 times by 3 tests: end of blockExecuted by:
| 275 | ||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | int QHttpNetworkConnectionPrivate::indexOf(QAbstractSocket *socket) const | - | ||||||||||||||||||
| 184 | { | - | ||||||||||||||||||
| 185 | for (int i = 0; i < channelCount; ++i)
| 0-16109 | ||||||||||||||||||
| 186 | if (channels[i].socket == socket)
| 7294-8815 | ||||||||||||||||||
| 187 | return i; executed 7294 times by 8 tests: return i;Executed by:
| 7294 | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | qFatal("Called with unknown socket object."); | - | ||||||||||||||||||
| 190 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 191 | } | - | ||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | // If the connection is in the HostLookupPendening state channel errors should not always be | - | ||||||||||||||||||
| 194 | // emitted. This function will check the status of the connection channels if we | - | ||||||||||||||||||
| 195 | // have not decided the networkLayerState and will return true if the channel error | - | ||||||||||||||||||
| 196 | // should be emitted by the channel. | - | ||||||||||||||||||
| 197 | bool QHttpNetworkConnectionPrivate::shouldEmitChannelError(QAbstractSocket *socket) | - | ||||||||||||||||||
| 198 | { | - | ||||||||||||||||||
| 199 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | bool emitError = true; | - | ||||||||||||||||||
| 202 | int i = indexOf(socket); | - | ||||||||||||||||||
| 203 | int otherSocket = (i == 0 ? 1 : 0);
| 27-125 | ||||||||||||||||||
| 204 | - | |||||||||||||||||||
| 205 | // If the IPv4 connection still isn't started we need to start it now. | - | ||||||||||||||||||
| 206 | if (delayedConnectionTimer.isActive()) {
| 30-122 | ||||||||||||||||||
| 207 | delayedConnectionTimer.stop(); | - | ||||||||||||||||||
| 208 | channels[otherSocket].ensureConnection(); | - | ||||||||||||||||||
| 209 | } executed 122 times by 2 tests: end of blockExecuted by:
| 122 | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | if (channelCount == 1) {
| 3-149 | ||||||||||||||||||
| 212 | if (networkLayerState == HostLookupPending || networkLayerState == IPv4or6)
| 0-3 | ||||||||||||||||||
| 213 | networkLayerState = QHttpNetworkConnectionPrivate::Unknown; never executed: networkLayerState = QHttpNetworkConnectionPrivate::Unknown; | 0 | ||||||||||||||||||
| 214 | channels[0].close(); | - | ||||||||||||||||||
| 215 | emitError = true; | - | ||||||||||||||||||
| 216 | } else { executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 217 | if (networkLayerState == HostLookupPending || networkLayerState == IPv4or6) {
| 0-149 | ||||||||||||||||||
| 218 | if (channels[otherSocket].isSocketBusy() && (channels[otherSocket].state != QHttpNetworkConnectionChannel::ClosingState)) {
| 0-122 | ||||||||||||||||||
| 219 | // this was the first socket to fail. | - | ||||||||||||||||||
| 220 | channels[i].close(); | - | ||||||||||||||||||
| 221 | emitError = false; | - | ||||||||||||||||||
| 222 | } executed 122 times by 2 tests: end of blockExecuted by:
| 122 | ||||||||||||||||||
| 223 | else { | - | ||||||||||||||||||
| 224 | // Both connection attempts has failed. | - | ||||||||||||||||||
| 225 | networkLayerState = QHttpNetworkConnectionPrivate::Unknown; | - | ||||||||||||||||||
| 226 | channels[i].close(); | - | ||||||||||||||||||
| 227 | emitError = true; | - | ||||||||||||||||||
| 228 | } executed 2 times by 2 tests: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 229 | } else { | - | ||||||||||||||||||
| 230 | if (((networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (channels[i].networkLayerPreference != QAbstractSocket::IPv4Protocol))
| 0-25 | ||||||||||||||||||
| 231 | || ((networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (channels[i].networkLayerPreference != QAbstractSocket::IPv6Protocol))) {
| 0-25 | ||||||||||||||||||
| 232 | // First connection worked so this is the second one to complete and it failed. | - | ||||||||||||||||||
| 233 | channels[i].close(); | - | ||||||||||||||||||
| 234 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 235 | emitError = false; | - | ||||||||||||||||||
| 236 | } never executed: end of block | 0 | ||||||||||||||||||
| 237 | if (networkLayerState == QHttpNetworkConnectionPrivate::Unknown)
| 0-25 | ||||||||||||||||||
| 238 | qWarning("We got a connection error when networkLayerState is Unknown"); never executed: QMessageLogger(__FILE__, 238, __PRETTY_FUNCTION__).warning("We got a connection error when networkLayerState is Unknown"); | 0 | ||||||||||||||||||
| 239 | } executed 25 times by 2 tests: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 240 | } | - | ||||||||||||||||||
| 241 | return emitError; executed 152 times by 4 tests: return emitError;Executed by:
| 152 | ||||||||||||||||||
| 242 | } | - | ||||||||||||||||||
| 243 | - | |||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailable(const QHttpNetworkReply &reply) const | - | ||||||||||||||||||
| 246 | { | - | ||||||||||||||||||
| 247 | return reply.d_func()->responseData.byteAmount(); executed 12636 times by 1 test: return reply.d_func()->responseData.byteAmount();Executed by:
| 12636 | ||||||||||||||||||
| 248 | } | - | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const | - | ||||||||||||||||||
| 251 | { | - | ||||||||||||||||||
| 252 | return reply.d_func()->responseData.sizeNextBlock(); never executed: return reply.d_func()->responseData.sizeNextBlock(); | 0 | ||||||||||||||||||
| 253 | } | - | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair) | - | ||||||||||||||||||
| 256 | { | - | ||||||||||||||||||
| 257 | QHttpNetworkRequest &request = messagePair.first; | - | ||||||||||||||||||
| 258 | QHttpNetworkReply *reply = messagePair.second; | - | ||||||||||||||||||
| 259 | - | |||||||||||||||||||
| 260 | // add missing fields for the request | - | ||||||||||||||||||
| 261 | QByteArray value; | - | ||||||||||||||||||
| 262 | // check if Content-Length is provided | - | ||||||||||||||||||
| 263 | QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice(); | - | ||||||||||||||||||
| 264 | if (uploadByteDevice) {
| 201-1436 | ||||||||||||||||||
| 265 | const qint64 contentLength = request.contentLength(); | - | ||||||||||||||||||
| 266 | const qint64 uploadDeviceSize = uploadByteDevice->size(); | - | ||||||||||||||||||
| 267 | if (contentLength != -1 && uploadDeviceSize != -1) {
| 1-131 | ||||||||||||||||||
| 268 | // both values known, take the smaller one. | - | ||||||||||||||||||
| 269 | request.setContentLength(qMin(uploadDeviceSize, contentLength)); | - | ||||||||||||||||||
| 270 | } else if (contentLength == -1 && uploadDeviceSize != -1) { executed 130 times by 3 tests: end of blockExecuted by:
| 0-130 | ||||||||||||||||||
| 271 | // content length not supplied by user, but the upload device knows it | - | ||||||||||||||||||
| 272 | request.setContentLength(uploadDeviceSize); | - | ||||||||||||||||||
| 273 | } else if (contentLength != -1 && uploadDeviceSize == -1) { executed 70 times by 2 tests: end of blockExecuted by:
| 0-70 | ||||||||||||||||||
| 274 | // everything OK, the user supplied us the contentLength | - | ||||||||||||||||||
| 275 | } else if (Q_UNLIKELY(contentLength == -1 && uploadDeviceSize == -1)) { executed 1 time by 1 test: end of blockExecuted by:
| 0-1 | ||||||||||||||||||
| 276 | qFatal("QHttpNetworkConnectionPrivate: Neither content-length nor upload device size were given"); | - | ||||||||||||||||||
| 277 | } never executed: end of block | 0 | ||||||||||||||||||
| 278 | } executed 201 times by 4 tests: end of blockExecuted by:
| 201 | ||||||||||||||||||
| 279 | // set the Connection/Proxy-Connection: Keep-Alive headers | - | ||||||||||||||||||
| 280 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 281 | if (networkProxy.type() == QNetworkProxy::HttpCachingProxy) {
| 8-1629 | ||||||||||||||||||
| 282 | value = request.headerField("proxy-connection"); | - | ||||||||||||||||||
| 283 | if (value.isEmpty())
| 0-8 | ||||||||||||||||||
| 284 | request.setHeaderField("Proxy-Connection", "Keep-Alive"); executed 8 times by 1 test: request.setHeaderField("Proxy-Connection", "Keep-Alive");Executed by:
| 8 | ||||||||||||||||||
| 285 | } else { executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 286 | #endif | - | ||||||||||||||||||
| 287 | value = request.headerField("connection"); | - | ||||||||||||||||||
| 288 | if (value.isEmpty())
| 0-1629 | ||||||||||||||||||
| 289 | request.setHeaderField("Connection", "Keep-Alive"); executed 1629 times by 8 tests: request.setHeaderField("Connection", "Keep-Alive");Executed by:
| 1629 | ||||||||||||||||||
| 290 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 291 | } executed 1629 times by 8 tests: end of blockExecuted by:
| 1629 | ||||||||||||||||||
| 292 | #endif | - | ||||||||||||||||||
| 293 | - | |||||||||||||||||||
| 294 | // If the request had a accept-encoding set, we better not mess | - | ||||||||||||||||||
| 295 | // with it. If it was not set, we announce that we understand gzip | - | ||||||||||||||||||
| 296 | // and remember this fact in request.d->autoDecompress so that | - | ||||||||||||||||||
| 297 | // we can later decompress the HTTP reply if it has such an | - | ||||||||||||||||||
| 298 | // encoding. | - | ||||||||||||||||||
| 299 | value = request.headerField("accept-encoding"); | - | ||||||||||||||||||
| 300 | if (value.isEmpty()) {
| 2-1635 | ||||||||||||||||||
| 301 | #ifndef QT_NO_COMPRESS | - | ||||||||||||||||||
| 302 | request.setHeaderField("Accept-Encoding", "gzip, deflate"); | - | ||||||||||||||||||
| 303 | request.d->autoDecompress = true; | - | ||||||||||||||||||
| 304 | #else | - | ||||||||||||||||||
| 305 | // if zlib is not available set this to false always | - | ||||||||||||||||||
| 306 | request.d->autoDecompress = false; | - | ||||||||||||||||||
| 307 | #endif | - | ||||||||||||||||||
| 308 | } executed 1635 times by 8 tests: end of blockExecuted by:
| 1635 | ||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | // some websites mandate an accept-language header and fail | - | ||||||||||||||||||
| 311 | // if it is not sent. This is a problem with the website and | - | ||||||||||||||||||
| 312 | // not with us, but we work around this by setting | - | ||||||||||||||||||
| 313 | // one always. | - | ||||||||||||||||||
| 314 | value = request.headerField("accept-language"); | - | ||||||||||||||||||
| 315 | if (value.isEmpty()) {
| 0-1637 | ||||||||||||||||||
| 316 | QString systemLocale = QLocale::system().name().replace(QChar::fromLatin1('_'),QChar::fromLatin1('-')); | - | ||||||||||||||||||
| 317 | QString acceptLanguage; | - | ||||||||||||||||||
| 318 | if (systemLocale == QLatin1String("C"))
| 0-1637 | ||||||||||||||||||
| 319 | acceptLanguage = QString::fromLatin1("en,*"); never executed: acceptLanguage = QString::fromLatin1("en,*"); | 0 | ||||||||||||||||||
| 320 | else if (systemLocale.startsWith(QLatin1String("en-")))
| 0-1637 | ||||||||||||||||||
| 321 | acceptLanguage = QString::fromLatin1("%1,*").arg(systemLocale); executed 1637 times by 8 tests: acceptLanguage = QString::fromLatin1("%1,*").arg(systemLocale);Executed by:
| 1637 | ||||||||||||||||||
| 322 | else | - | ||||||||||||||||||
| 323 | acceptLanguage = QString::fromLatin1("%1,en,*").arg(systemLocale); never executed: acceptLanguage = QString::fromLatin1("%1,en,*").arg(systemLocale); | 0 | ||||||||||||||||||
| 324 | request.setHeaderField("Accept-Language", acceptLanguage.toLatin1()); | - | ||||||||||||||||||
| 325 | } executed 1637 times by 8 tests: end of blockExecuted by:
| 1637 | ||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | // set the User Agent | - | ||||||||||||||||||
| 328 | value = request.headerField("user-agent"); | - | ||||||||||||||||||
| 329 | if (value.isEmpty())
| 4-1633 | ||||||||||||||||||
| 330 | request.setHeaderField("User-Agent", "Mozilla/5.0"); executed 1633 times by 7 tests: request.setHeaderField("User-Agent", "Mozilla/5.0");Executed by:
| 1633 | ||||||||||||||||||
| 331 | // set the host | - | ||||||||||||||||||
| 332 | value = request.headerField("host"); | - | ||||||||||||||||||
| 333 | if (value.isEmpty()) {
| 1-1636 | ||||||||||||||||||
| 334 | QHostAddress add; | - | ||||||||||||||||||
| 335 | QByteArray host; | - | ||||||||||||||||||
| 336 | if (add.setAddress(hostName)) {
| 43-1593 | ||||||||||||||||||
| 337 | if (add.protocol() == QAbstractSocket::IPv6Protocol)
| 1-42 | ||||||||||||||||||
| 338 | host = '[' + hostName.toLatin1() + ']'; //format the ipv6 in the standard way executed 1 time by 1 test: host = '[' + hostName.toLatin1() + ']';Executed by:
| 1 | ||||||||||||||||||
| 339 | else | - | ||||||||||||||||||
| 340 | host = hostName.toLatin1(); executed 42 times by 3 tests: host = hostName.toLatin1();Executed by:
| 42 | ||||||||||||||||||
| 341 | - | |||||||||||||||||||
| 342 | } else { | - | ||||||||||||||||||
| 343 | host = QUrl::toAce(hostName); | - | ||||||||||||||||||
| 344 | } executed 1593 times by 7 tests: end of blockExecuted by:
| 1593 | ||||||||||||||||||
| 345 | - | |||||||||||||||||||
| 346 | int port = request.url().port(); | - | ||||||||||||||||||
| 347 | if (port != -1) {
| 173-1463 | ||||||||||||||||||
| 348 | host += ':'; | - | ||||||||||||||||||
| 349 | host += QByteArray::number(port); | - | ||||||||||||||||||
| 350 | } executed 173 times by 3 tests: end of blockExecuted by:
| 173 | ||||||||||||||||||
| 351 | - | |||||||||||||||||||
| 352 | request.setHeaderField("Host", host); | - | ||||||||||||||||||
| 353 | } executed 1636 times by 7 tests: end of blockExecuted by:
| 1636 | ||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | reply->d_func()->requestIsPrepared = true; | - | ||||||||||||||||||
| 356 | } executed 1637 times by 8 tests: end of blockExecuted by:
| 1637 | ||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | - | |||||||||||||||||||
| 360 | - | |||||||||||||||||||
| 361 | void QHttpNetworkConnectionPrivate::emitReplyError(QAbstractSocket *socket, | - | ||||||||||||||||||
| 362 | QHttpNetworkReply *reply, | - | ||||||||||||||||||
| 363 | QNetworkReply::NetworkError errorCode) | - | ||||||||||||||||||
| 364 | { | - | ||||||||||||||||||
| 365 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
| 366 | - | |||||||||||||||||||
| 367 | int i = 0; | - | ||||||||||||||||||
| 368 | if (socket)
| 4-5 | ||||||||||||||||||
| 369 | i = indexOf(socket); executed 5 times by 2 tests: i = indexOf(socket);Executed by:
| 5 | ||||||||||||||||||
| 370 | - | |||||||||||||||||||
| 371 | if (reply) {
| 0-9 | ||||||||||||||||||
| 372 | // this error matters only to this reply | - | ||||||||||||||||||
| 373 | reply->d_func()->errorString = errorDetail(errorCode, socket); | - | ||||||||||||||||||
| 374 | emit reply->finishedWithError(errorCode, reply->d_func()->errorString); | - | ||||||||||||||||||
| 375 | // remove the corrupt data if any | - | ||||||||||||||||||
| 376 | reply->d_func()->eraseData(); | - | ||||||||||||||||||
| 377 | - | |||||||||||||||||||
| 378 | // Clean the channel | - | ||||||||||||||||||
| 379 | channels[i].close(); | - | ||||||||||||||||||
| 380 | channels[i].reply = 0; | - | ||||||||||||||||||
| 381 | if (channels[i].protocolHandler)
| 4-5 | ||||||||||||||||||
| 382 | channels[i].protocolHandler->setReply(0); executed 5 times by 2 tests: channels[i].protocolHandler->setReply(0);Executed by:
| 5 | ||||||||||||||||||
| 383 | channels[i].request = QHttpNetworkRequest(); | - | ||||||||||||||||||
| 384 | if (socket)
| 4-5 | ||||||||||||||||||
| 385 | channels[i].requeueCurrentlyPipelinedRequests(); executed 5 times by 2 tests: channels[i].requeueCurrentlyPipelinedRequests();Executed by:
| 5 | ||||||||||||||||||
| 386 | - | |||||||||||||||||||
| 387 | // send the next request | - | ||||||||||||||||||
| 388 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 389 | } executed 9 times by 4 tests: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 390 | } executed 9 times by 4 tests: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | void QHttpNetworkConnectionPrivate::copyCredentials(int fromChannel, QAuthenticator *auth, bool isProxy) | - | ||||||||||||||||||
| 393 | { | - | ||||||||||||||||||
| 394 | Q_ASSERT(auth); | - | ||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | // NTLM is a multi phase authentication. Copying credentials between authenticators would mess things up. | - | ||||||||||||||||||
| 397 | if (fromChannel >= 0) {
| 0-201 | ||||||||||||||||||
| 398 | if (!isProxy && channels[fromChannel].authMethod == QAuthenticatorPrivate::Ntlm)
| 0-135 | ||||||||||||||||||
| 399 | return; never executed: return; | 0 | ||||||||||||||||||
| 400 | if (isProxy && channels[fromChannel].proxyAuthMethod == QAuthenticatorPrivate::Ntlm)
| 0-135 | ||||||||||||||||||
| 401 | return; never executed: return; | 0 | ||||||||||||||||||
| 402 | } executed 201 times by 3 tests: end of blockExecuted by:
| 201 | ||||||||||||||||||
| 403 | - | |||||||||||||||||||
| 404 | // select another channel | - | ||||||||||||||||||
| 405 | QAuthenticator* otherAuth = 0; | - | ||||||||||||||||||
| 406 | for (int i = 0; i < channelCount; ++i) {
| 201-1191 | ||||||||||||||||||
| 407 | if (i == fromChannel)
| 201-990 | ||||||||||||||||||
| 408 | continue; executed 201 times by 3 tests: continue;Executed by:
| 201 | ||||||||||||||||||
| 409 | if (isProxy)
| 315-675 | ||||||||||||||||||
| 410 | otherAuth = &channels[i].proxyAuthenticator; executed 315 times by 1 test: otherAuth = &channels[i].proxyAuthenticator;Executed by:
| 315 | ||||||||||||||||||
| 411 | else | - | ||||||||||||||||||
| 412 | otherAuth = &channels[i].authenticator; executed 675 times by 2 tests: otherAuth = &channels[i].authenticator;Executed by:
| 675 | ||||||||||||||||||
| 413 | // if the credentials are different, copy them | - | ||||||||||||||||||
| 414 | if (otherAuth->user().compare(auth->user()))
| 255-735 | ||||||||||||||||||
| 415 | otherAuth->setUser(auth->user()); executed 735 times by 2 tests: otherAuth->setUser(auth->user());Executed by:
| 735 | ||||||||||||||||||
| 416 | if (otherAuth->password().compare(auth->password()))
| 245-745 | ||||||||||||||||||
| 417 | otherAuth->setPassword(auth->password()); executed 745 times by 2 tests: otherAuth->setPassword(auth->password());Executed by:
| 745 | ||||||||||||||||||
| 418 | } executed 990 times by 2 tests: end of blockExecuted by:
| 990 | ||||||||||||||||||
| 419 | } executed 201 times by 3 tests: end of blockExecuted by:
| 201 | ||||||||||||||||||
| 420 | - | |||||||||||||||||||
| 421 | - | |||||||||||||||||||
| 422 | // handles the authentication for one channel and eventually re-starts the other channels | - | ||||||||||||||||||
| 423 | bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, | - | ||||||||||||||||||
| 424 | bool isProxy, bool &resend) | - | ||||||||||||||||||
| 425 | { | - | ||||||||||||||||||
| 426 | Q_ASSERT(socket); | - | ||||||||||||||||||
| 427 | Q_ASSERT(reply); | - | ||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | resend = false; | - | ||||||||||||||||||
| 430 | //create the response header to be used with QAuthenticatorPrivate. | - | ||||||||||||||||||
| 431 | QList<QPair<QByteArray, QByteArray> > fields = reply->header(); | - | ||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | //find out the type of authentication protocol requested. | - | ||||||||||||||||||
| 434 | QAuthenticatorPrivate::Method authMethod = reply->d_func()->authenticationMethod(isProxy); | - | ||||||||||||||||||
| 435 | if (authMethod != QAuthenticatorPrivate::None) {
| 3-353 | ||||||||||||||||||
| 436 | int i = indexOf(socket); | - | ||||||||||||||||||
| 437 | //Use a single authenticator for all domains. ### change later to use domain/realm | - | ||||||||||||||||||
| 438 | QAuthenticator* auth = 0; | - | ||||||||||||||||||
| 439 | if (isProxy) {
| 53-300 | ||||||||||||||||||
| 440 | auth = &channels[i].proxyAuthenticator; | - | ||||||||||||||||||
| 441 | channels[i].proxyAuthMethod = authMethod; | - | ||||||||||||||||||
| 442 | } else { executed 53 times by 1 test: end of blockExecuted by:
| 53 | ||||||||||||||||||
| 443 | auth = &channels[i].authenticator; | - | ||||||||||||||||||
| 444 | channels[i].authMethod = authMethod; | - | ||||||||||||||||||
| 445 | } executed 300 times by 2 tests: end of blockExecuted by:
| 300 | ||||||||||||||||||
| 446 | //proceed with the authentication. | - | ||||||||||||||||||
| 447 | if (auth->isNull())
| 0-353 | ||||||||||||||||||
| 448 | auth->detach(); never executed: auth->detach(); | 0 | ||||||||||||||||||
| 449 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(*auth); | - | ||||||||||||||||||
| 450 | priv->parseHttpResponse(fields, isProxy); | - | ||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | if (priv->phase == QAuthenticatorPrivate::Done) {
| 174-179 | ||||||||||||||||||
| 453 | pauseConnection(); | - | ||||||||||||||||||
| 454 | if (!isProxy) {
| 27-152 | ||||||||||||||||||
| 455 | if (channels[i].authenticationCredentialsSent) {
| 52-100 | ||||||||||||||||||
| 456 | auth->detach(); | - | ||||||||||||||||||
| 457 | priv = QAuthenticatorPrivate::getPrivate(*auth); | - | ||||||||||||||||||
| 458 | priv->hasFailed = true; | - | ||||||||||||||||||
| 459 | priv->phase = QAuthenticatorPrivate::Done; | - | ||||||||||||||||||
| 460 | channels[i].authenticationCredentialsSent = false; | - | ||||||||||||||||||
| 461 | } executed 52 times by 2 tests: end of blockExecuted by:
| 52 | ||||||||||||||||||
| 462 | emit reply->authenticationRequired(reply->request(), auth); | - | ||||||||||||||||||
| 463 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 464 | } else { executed 152 times by 2 tests: end of blockExecuted by:
| 152 | ||||||||||||||||||
| 465 | if (channels[i].proxyCredentialsSent) {
| 2-25 | ||||||||||||||||||
| 466 | auth->detach(); | - | ||||||||||||||||||
| 467 | priv = QAuthenticatorPrivate::getPrivate(*auth); | - | ||||||||||||||||||
| 468 | priv->hasFailed = true; | - | ||||||||||||||||||
| 469 | priv->phase = QAuthenticatorPrivate::Done; | - | ||||||||||||||||||
| 470 | channels[i].proxyCredentialsSent = false; | - | ||||||||||||||||||
| 471 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 472 | emit reply->proxyAuthenticationRequired(networkProxy, auth); | - | ||||||||||||||||||
| 473 | #endif | - | ||||||||||||||||||
| 474 | } executed 27 times by 1 test: end of blockExecuted by:
| 27 | ||||||||||||||||||
| 475 | resumeConnection(); | - | ||||||||||||||||||
| 476 | - | |||||||||||||||||||
| 477 | if (priv->phase != QAuthenticatorPrivate::Done) {
| 38-141 | ||||||||||||||||||
| 478 | // send any pending requests | - | ||||||||||||||||||
| 479 | copyCredentials(i, auth, isProxy); | - | ||||||||||||||||||
| 480 | } executed 141 times by 2 tests: end of blockExecuted by:
| 141 | ||||||||||||||||||
| 481 | } else if (priv->phase == QAuthenticatorPrivate::Start) { executed 179 times by 2 tests: end of blockExecuted by:
| 0-179 | ||||||||||||||||||
| 482 | // If the url's authenticator has a 'user' set we will end up here (phase is only set to 'Done' by | - | ||||||||||||||||||
| 483 | // parseHttpResponse above if 'user' is empty). So if credentials were supplied with the request, | - | ||||||||||||||||||
| 484 | // such as in the case of an XMLHttpRequest, this is our only opportunity to cache them. | - | ||||||||||||||||||
| 485 | emit reply->cacheCredentials(reply->request(), auth); | - | ||||||||||||||||||
| 486 | } executed 174 times by 2 tests: end of blockExecuted by:
| 174 | ||||||||||||||||||
| 487 | // - Changing values in QAuthenticator will reset the 'phase'. Therefore if it is still "Done" | - | ||||||||||||||||||
| 488 | // then nothing was filled in by the user or the cache | - | ||||||||||||||||||
| 489 | // - If withCredentials has been set to false (e.g. by Qt WebKit for a cross-origin XMLHttpRequest) then | - | ||||||||||||||||||
| 490 | // we need to bail out if authentication is required. | - | ||||||||||||||||||
| 491 | if (priv->phase == QAuthenticatorPrivate::Done || !reply->request().withCredentials()) {
| 0-315 | ||||||||||||||||||
| 492 | // Reset authenticator so the next request on that channel does not get messed up | - | ||||||||||||||||||
| 493 | auth = 0; | - | ||||||||||||||||||
| 494 | if (isProxy)
| 3-35 | ||||||||||||||||||
| 495 | channels[i].proxyAuthenticator = QAuthenticator(); executed 3 times by 1 test: channels[i].proxyAuthenticator = QAuthenticator();Executed by:
| 3 | ||||||||||||||||||
| 496 | else | - | ||||||||||||||||||
| 497 | channels[i].authenticator = QAuthenticator(); executed 35 times by 2 tests: channels[i].authenticator = QAuthenticator();Executed by:
| 35 | ||||||||||||||||||
| 498 | - | |||||||||||||||||||
| 499 | // authentication is cancelled, send the current contents to the user. | - | ||||||||||||||||||
| 500 | emit channels[i].reply->headerChanged(); | - | ||||||||||||||||||
| 501 | emit channels[i].reply->readyRead(); | - | ||||||||||||||||||
| 502 | QNetworkReply::NetworkError errorCode = | - | ||||||||||||||||||
| 503 | isProxy
| 3-35 | ||||||||||||||||||
| 504 | ? QNetworkReply::ProxyAuthenticationRequiredError | - | ||||||||||||||||||
| 505 | : QNetworkReply::AuthenticationRequiredError; | - | ||||||||||||||||||
| 506 | reply->d_func()->errorString = errorDetail(errorCode, socket); | - | ||||||||||||||||||
| 507 | emit reply->finishedWithError(errorCode, reply->d_func()->errorString); | - | ||||||||||||||||||
| 508 | // ### at this point the reply could be deleted | - | ||||||||||||||||||
| 509 | return true; executed 38 times by 2 tests: return true;Executed by:
| 38 | ||||||||||||||||||
| 510 | } | - | ||||||||||||||||||
| 511 | //resend the request | - | ||||||||||||||||||
| 512 | resend = true; | - | ||||||||||||||||||
| 513 | return true; executed 315 times by 2 tests: return true;Executed by:
| 315 | ||||||||||||||||||
| 514 | } | - | ||||||||||||||||||
| 515 | return false; executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||||||||
| 516 | } | - | ||||||||||||||||||
| 517 | - | |||||||||||||||||||
| 518 | QUrl QHttpNetworkConnectionPrivate::parseRedirectResponse(QAbstractSocket *socket, QHttpNetworkReply *reply) | - | ||||||||||||||||||
| 519 | { | - | ||||||||||||||||||
| 520 | if (!reply->request().isFollowRedirects())
| 3-6 | ||||||||||||||||||
| 521 | return QUrl(); executed 3 times by 1 test: return QUrl();Executed by:
| 3 | ||||||||||||||||||
| 522 | - | |||||||||||||||||||
| 523 | QUrl rUrl; | - | ||||||||||||||||||
| 524 | const QList<QPair<QByteArray, QByteArray> > fields = reply->header(); | - | ||||||||||||||||||
| 525 | for (const QNetworkReply::RawHeaderPair &header : fields) { | - | ||||||||||||||||||
| 526 | if (header.first.toLower() == "location") {
| 6 | ||||||||||||||||||
| 527 | rUrl = QUrl::fromEncoded(header.second); | - | ||||||||||||||||||
| 528 | break; executed 6 times by 1 test: break;Executed by:
| 6 | ||||||||||||||||||
| 529 | } | - | ||||||||||||||||||
| 530 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 531 | - | |||||||||||||||||||
| 532 | // If the location url is invalid/empty, we emit ProtocolUnknownError | - | ||||||||||||||||||
| 533 | if (!rUrl.isValid()) {
| 0-6 | ||||||||||||||||||
| 534 | emitReplyError(socket, reply, QNetworkReply::ProtocolUnknownError); | - | ||||||||||||||||||
| 535 | return QUrl(); never executed: return QUrl(); | 0 | ||||||||||||||||||
| 536 | } | - | ||||||||||||||||||
| 537 | - | |||||||||||||||||||
| 538 | // Check if we have exceeded max redirects allowed | - | ||||||||||||||||||
| 539 | if (reply->request().redirectCount() <= 0) {
| 1-5 | ||||||||||||||||||
| 540 | emitReplyError(socket, reply, QNetworkReply::TooManyRedirectsError); | - | ||||||||||||||||||
| 541 | return QUrl(); executed 1 time by 1 test: return QUrl();Executed by:
| 1 | ||||||||||||||||||
| 542 | } | - | ||||||||||||||||||
| 543 | - | |||||||||||||||||||
| 544 | // Resolve the URL if it's relative | - | ||||||||||||||||||
| 545 | if (rUrl.isRelative())
| 0-5 | ||||||||||||||||||
| 546 | rUrl = reply->request().url().resolved(rUrl); never executed: rUrl = reply->request().url().resolved(rUrl); | 0 | ||||||||||||||||||
| 547 | - | |||||||||||||||||||
| 548 | // Check redirect url protocol | - | ||||||||||||||||||
| 549 | QString scheme = rUrl.scheme(); | - | ||||||||||||||||||
| 550 | if (scheme == QLatin1String("http") || scheme == QLatin1String("https")) {
| 0-5 | ||||||||||||||||||
| 551 | QString previousUrlScheme = reply->request().url().scheme(); | - | ||||||||||||||||||
| 552 | // Check if we're doing an unsecure redirect (https -> http) | - | ||||||||||||||||||
| 553 | if (previousUrlScheme == QLatin1String("https")
| 0-5 | ||||||||||||||||||
| 554 | && scheme == QLatin1String("http")) {
| 0 | ||||||||||||||||||
| 555 | emitReplyError(socket, reply, QNetworkReply::InsecureRedirectError); | - | ||||||||||||||||||
| 556 | return QUrl(); never executed: return QUrl(); | 0 | ||||||||||||||||||
| 557 | } | - | ||||||||||||||||||
| 558 | } else { executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 559 | emitReplyError(socket, reply, QNetworkReply::ProtocolUnknownError); | - | ||||||||||||||||||
| 560 | return QUrl(); never executed: return QUrl(); | 0 | ||||||||||||||||||
| 561 | } | - | ||||||||||||||||||
| 562 | return rUrl; executed 5 times by 1 test: return rUrl;Executed by:
| 5 | ||||||||||||||||||
| 563 | } | - | ||||||||||||||||||
| 564 | - | |||||||||||||||||||
| 565 | void QHttpNetworkConnectionPrivate::createAuthorization(QAbstractSocket *socket, QHttpNetworkRequest &request) | - | ||||||||||||||||||
| 566 | { | - | ||||||||||||||||||
| 567 | Q_ASSERT(socket); | - | ||||||||||||||||||
| 568 | - | |||||||||||||||||||
| 569 | int i = indexOf(socket); | - | ||||||||||||||||||
| 570 | - | |||||||||||||||||||
| 571 | // Send "Authorization" header, but not if it's NTLM and the socket is already authenticated. | - | ||||||||||||||||||
| 572 | if (channels[i].authMethod != QAuthenticatorPrivate::None) {
| 172-1149 | ||||||||||||||||||
| 573 | if ((channels[i].authMethod != QAuthenticatorPrivate::Ntlm && request.headerField("Authorization").isEmpty()) || channels[i].lastStatus == 401) {
| 0-172 | ||||||||||||||||||
| 574 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(channels[i].authenticator); | - | ||||||||||||||||||
| 575 | if (priv && priv->method != QAuthenticatorPrivate::None) {
| 0-172 | ||||||||||||||||||
| 576 | QByteArray response = priv->calculateResponse(request.methodName(), request.uri(false)); | - | ||||||||||||||||||
| 577 | request.setHeaderField("Authorization", response); | - | ||||||||||||||||||
| 578 | channels[i].authenticationCredentialsSent = true; | - | ||||||||||||||||||
| 579 | } executed 152 times by 2 tests: end of blockExecuted by:
| 152 | ||||||||||||||||||
| 580 | } executed 172 times by 2 tests: end of blockExecuted by:
| 172 | ||||||||||||||||||
| 581 | } executed 172 times by 2 tests: end of blockExecuted by:
| 172 | ||||||||||||||||||
| 582 | - | |||||||||||||||||||
| 583 | // Send "Proxy-Authorization" header, but not if it's NTLM and the socket is already authenticated. | - | ||||||||||||||||||
| 584 | if (channels[i].proxyAuthMethod != QAuthenticatorPrivate::None) {
| 40-1281 | ||||||||||||||||||
| 585 | if (!(channels[i].proxyAuthMethod == QAuthenticatorPrivate::Ntlm && channels[i].lastStatus != 407)) {
| 0-40 | ||||||||||||||||||
| 586 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(channels[i].proxyAuthenticator); | - | ||||||||||||||||||
| 587 | if (priv && priv->method != QAuthenticatorPrivate::None) {
| 0-40 | ||||||||||||||||||
| 588 | QByteArray response = priv->calculateResponse(request.methodName(), request.uri(false)); | - | ||||||||||||||||||
| 589 | request.setHeaderField("Proxy-Authorization", response); | - | ||||||||||||||||||
| 590 | channels[i].proxyCredentialsSent = true; | - | ||||||||||||||||||
| 591 | } executed 38 times by 1 test: end of blockExecuted by:
| 38 | ||||||||||||||||||
| 592 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||
| 593 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||
| 594 | } executed 1321 times by 8 tests: end of blockExecuted by:
| 1321 | ||||||||||||||||||
| 595 | - | |||||||||||||||||||
| 596 | QHttpNetworkReply* QHttpNetworkConnectionPrivate::queueRequest(const QHttpNetworkRequest &request) | - | ||||||||||||||||||
| 597 | { | - | ||||||||||||||||||
| 598 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
| 599 | - | |||||||||||||||||||
| 600 | // The reply component of the pair is created initially. | - | ||||||||||||||||||
| 601 | QHttpNetworkReply *reply = new QHttpNetworkReply(request.url()); | - | ||||||||||||||||||
| 602 | reply->setRequest(request); | - | ||||||||||||||||||
| 603 | reply->d_func()->connection = q; | - | ||||||||||||||||||
| 604 | reply->d_func()->connectionChannel = &channels[0]; // will have the correct one set later | - | ||||||||||||||||||
| 605 | HttpMessagePair pair = qMakePair(request, reply); | - | ||||||||||||||||||
| 606 | - | |||||||||||||||||||
| 607 | if (request.isPreConnect())
| 0-1646 | ||||||||||||||||||
| 608 | preConnectRequests++; never executed: preConnectRequests++; | 0 | ||||||||||||||||||
| 609 | - | |||||||||||||||||||
| 610 | if (connectionType == QHttpNetworkConnection::ConnectionTypeHTTP) {
| 112-1534 | ||||||||||||||||||
| 611 | switch (request.priority()) { | - | ||||||||||||||||||
| 612 | case QHttpNetworkRequest::HighPriority: executed 116 times by 1 test: case QHttpNetworkRequest::HighPriority:Executed by:
| 116 | ||||||||||||||||||
| 613 | highPriorityQueue.prepend(pair); | - | ||||||||||||||||||
| 614 | break; executed 116 times by 1 test: break;Executed by:
| 116 | ||||||||||||||||||
| 615 | case QHttpNetworkRequest::NormalPriority: executed 1362 times by 8 tests: case QHttpNetworkRequest::NormalPriority:Executed by:
| 1362 | ||||||||||||||||||
| 616 | case QHttpNetworkRequest::LowPriority: executed 56 times by 1 test: case QHttpNetworkRequest::LowPriority:Executed by:
| 56 | ||||||||||||||||||
| 617 | lowPriorityQueue.prepend(pair); | - | ||||||||||||||||||
| 618 | break; executed 1418 times by 8 tests: break;Executed by:
| 1418 | ||||||||||||||||||
| 619 | } | - | ||||||||||||||||||
| 620 | } executed 1534 times by 8 tests: end of blockExecuted by:
| 1534 | ||||||||||||||||||
| 621 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 622 | else { // SPDY | - | ||||||||||||||||||
| 623 | if (!pair.second->d_func()->requestIsPrepared)
| 0-112 | ||||||||||||||||||
| 624 | prepareRequest(pair); executed 112 times by 1 test: prepareRequest(pair);Executed by:
| 112 | ||||||||||||||||||
| 625 | channels[0].spdyRequestsToSend.insertMulti(request.priority(), pair); | - | ||||||||||||||||||
| 626 | } executed 112 times by 1 test: end of blockExecuted by:
| 112 | ||||||||||||||||||
| 627 | #endif // QT_NO_SSL | - | ||||||||||||||||||
| 628 | - | |||||||||||||||||||
| 629 | // For Happy Eyeballs the networkLayerState is set to Unknown | - | ||||||||||||||||||
| 630 | // untill we have started the first connection attempt. So no | - | ||||||||||||||||||
| 631 | // request will be started untill we know if IPv4 or IPv6 | - | ||||||||||||||||||
| 632 | // should be used. | - | ||||||||||||||||||
| 633 | if (networkLayerState == Unknown || networkLayerState == HostLookupPending) {
| 0-1063 | ||||||||||||||||||
| 634 | startHostInfoLookup(); | - | ||||||||||||||||||
| 635 | } else if ( networkLayerState == IPv4 || networkLayerState == IPv6 ) { executed 583 times by 8 tests: end of blockExecuted by:
| 0-1061 | ||||||||||||||||||
| 636 | // this used to be called via invokeMethod and a QueuedConnection | - | ||||||||||||||||||
| 637 | // It is the only place _q_startNextRequest is called directly without going | - | ||||||||||||||||||
| 638 | // through the event loop using a QueuedConnection. | - | ||||||||||||||||||
| 639 | // This is dangerous because of recursion that might occur when emitting | - | ||||||||||||||||||
| 640 | // signals as DirectConnection from this code path. Therefore all signal | - | ||||||||||||||||||
| 641 | // emissions that can come out from this code path need to | - | ||||||||||||||||||
| 642 | // be QueuedConnection. | - | ||||||||||||||||||
| 643 | // We are currently trying to fine-tune this. | - | ||||||||||||||||||
| 644 | _q_startNextRequest(); | - | ||||||||||||||||||
| 645 | } executed 1061 times by 4 tests: end of blockExecuted by:
| 1061 | ||||||||||||||||||
| 646 | return reply; executed 1646 times by 8 tests: return reply;Executed by:
| 1646 | ||||||||||||||||||
| 647 | } | - | ||||||||||||||||||
| 648 | - | |||||||||||||||||||
| 649 | void QHttpNetworkConnectionPrivate::requeueRequest(const HttpMessagePair &pair) | - | ||||||||||||||||||
| 650 | { | - | ||||||||||||||||||
| 651 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
| 652 | - | |||||||||||||||||||
| 653 | QHttpNetworkRequest request = pair.first; | - | ||||||||||||||||||
| 654 | switch (request.priority()) { | - | ||||||||||||||||||
| 655 | case QHttpNetworkRequest::HighPriority: never executed: case QHttpNetworkRequest::HighPriority: | 0 | ||||||||||||||||||
| 656 | highPriorityQueue.prepend(pair); | - | ||||||||||||||||||
| 657 | break; never executed: break; | 0 | ||||||||||||||||||
| 658 | case QHttpNetworkRequest::NormalPriority: never executed: case QHttpNetworkRequest::NormalPriority: | 0 | ||||||||||||||||||
| 659 | case QHttpNetworkRequest::LowPriority: never executed: case QHttpNetworkRequest::LowPriority: | 0 | ||||||||||||||||||
| 660 | lowPriorityQueue.prepend(pair); | - | ||||||||||||||||||
| 661 | break; never executed: break; | 0 | ||||||||||||||||||
| 662 | } | - | ||||||||||||||||||
| 663 | - | |||||||||||||||||||
| 664 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 665 | } never executed: end of block | 0 | ||||||||||||||||||
| 666 | - | |||||||||||||||||||
| 667 | bool QHttpNetworkConnectionPrivate::dequeueRequest(QAbstractSocket *socket) | - | ||||||||||||||||||
| 668 | { | - | ||||||||||||||||||
| 669 | int i = 0; | - | ||||||||||||||||||
| 670 | if (socket)
| 4-1151 | ||||||||||||||||||
| 671 | i = indexOf(socket); executed 1151 times by 8 tests: i = indexOf(socket);Executed by:
| 1151 | ||||||||||||||||||
| 672 | - | |||||||||||||||||||
| 673 | if (!highPriorityQueue.isEmpty()) {
| 54-1101 | ||||||||||||||||||
| 674 | // remove from queue before sendRequest! else we might pipeline the same request again | - | ||||||||||||||||||
| 675 | HttpMessagePair messagePair = highPriorityQueue.takeLast(); | - | ||||||||||||||||||
| 676 | if (!messagePair.second->d_func()->requestIsPrepared)
| 0-54 | ||||||||||||||||||
| 677 | prepareRequest(messagePair); executed 54 times by 1 test: prepareRequest(messagePair);Executed by:
| 54 | ||||||||||||||||||
| 678 | updateChannel(i, messagePair); | - | ||||||||||||||||||
| 679 | return true; executed 54 times by 1 test: return true;Executed by:
| 54 | ||||||||||||||||||
| 680 | } | - | ||||||||||||||||||
| 681 | - | |||||||||||||||||||
| 682 | if (!lowPriorityQueue.isEmpty()) {
| 32-1069 | ||||||||||||||||||
| 683 | // remove from queue before sendRequest! else we might pipeline the same request again | - | ||||||||||||||||||
| 684 | HttpMessagePair messagePair = lowPriorityQueue.takeLast(); | - | ||||||||||||||||||
| 685 | if (!messagePair.second->d_func()->requestIsPrepared)
| 0-1069 | ||||||||||||||||||
| 686 | prepareRequest(messagePair); executed 1069 times by 8 tests: prepareRequest(messagePair);Executed by:
| 1069 | ||||||||||||||||||
| 687 | updateChannel(i, messagePair); | - | ||||||||||||||||||
| 688 | return true; executed 1069 times by 8 tests: return true;Executed by:
| 1069 | ||||||||||||||||||
| 689 | } | - | ||||||||||||||||||
| 690 | return false; executed 32 times by 3 tests: return false;Executed by:
| 32 | ||||||||||||||||||
| 691 | } | - | ||||||||||||||||||
| 692 | - | |||||||||||||||||||
| 693 | void QHttpNetworkConnectionPrivate::updateChannel(int i, const HttpMessagePair &messagePair) | - | ||||||||||||||||||
| 694 | { | - | ||||||||||||||||||
| 695 | channels[i].request = messagePair.first; | - | ||||||||||||||||||
| 696 | channels[i].reply = messagePair.second; | - | ||||||||||||||||||
| 697 | // Now that reply is assigned a channel, correct reply to channel association | - | ||||||||||||||||||
| 698 | // previously set in queueRequest. | - | ||||||||||||||||||
| 699 | channels[i].reply->d_func()->connectionChannel = &channels[i]; | - | ||||||||||||||||||
| 700 | } executed 1123 times by 8 tests: end of blockExecuted by:
| 1123 | ||||||||||||||||||
| 701 | - | |||||||||||||||||||
| 702 | QHttpNetworkRequest QHttpNetworkConnectionPrivate::predictNextRequest() const | - | ||||||||||||||||||
| 703 | { | - | ||||||||||||||||||
| 704 | if (!highPriorityQueue.isEmpty())
| 0-21 | ||||||||||||||||||
| 705 | return highPriorityQueue.last().first; never executed: return highPriorityQueue.last().first; | 0 | ||||||||||||||||||
| 706 | if (!lowPriorityQueue.isEmpty())
| 4-17 | ||||||||||||||||||
| 707 | return lowPriorityQueue.last().first; executed 17 times by 1 test: return lowPriorityQueue.last().first;Executed by:
| 17 | ||||||||||||||||||
| 708 | return QHttpNetworkRequest(); executed 4 times by 1 test: return QHttpNetworkRequest();Executed by:
| 4 | ||||||||||||||||||
| 709 | } | - | ||||||||||||||||||
| 710 | - | |||||||||||||||||||
| 711 | // this is called from _q_startNextRequest and when a request has been sent down a socket from the channel | - | ||||||||||||||||||
| 712 | void QHttpNetworkConnectionPrivate::fillPipeline(QAbstractSocket *socket) | - | ||||||||||||||||||
| 713 | { | - | ||||||||||||||||||
| 714 | // return fast if there is nothing to pipeline | - | ||||||||||||||||||
| 715 | if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty())
| 35-3929 | ||||||||||||||||||
| 716 | return; executed 35 times by 2 tests: return;Executed by:
| 35 | ||||||||||||||||||
| 717 | - | |||||||||||||||||||
| 718 | int i = indexOf(socket); | - | ||||||||||||||||||
| 719 | - | |||||||||||||||||||
| 720 | // return fast if there was no reply right now processed | - | ||||||||||||||||||
| 721 | if (channels[i].reply == 0)
| 33-4219 | ||||||||||||||||||
| 722 | return; executed 33 times by 1 test: return;Executed by:
| 33 | ||||||||||||||||||
| 723 | - | |||||||||||||||||||
| 724 | if (! (defaultPipelineLength - channels[i].alreadyPipelinedRequests.length() >= defaultRePipelineLength)) {
| 1034-3185 | ||||||||||||||||||
| 725 | return; executed 1034 times by 2 tests: return;Executed by:
| 1034 | ||||||||||||||||||
| 726 | } | - | ||||||||||||||||||
| 727 | - | |||||||||||||||||||
| 728 | if (channels[i].pipeliningSupported != QHttpNetworkConnectionChannel::PipeliningProbablySupported)
| 316-2869 | ||||||||||||||||||
| 729 | return; executed 316 times by 2 tests: return;Executed by:
| 316 | ||||||||||||||||||
| 730 | - | |||||||||||||||||||
| 731 | // the current request that is in must already support pipelining | - | ||||||||||||||||||
| 732 | if (!channels[i].request.isPipeliningAllowed())
| 270-2599 | ||||||||||||||||||
| 733 | return; executed 2599 times by 2 tests: return;Executed by:
| 2599 | ||||||||||||||||||
| 734 | - | |||||||||||||||||||
| 735 | // the current request must be a idempotent (right now we only check GET) | - | ||||||||||||||||||
| 736 | if (channels[i].request.operation() != QHttpNetworkRequest::Get)
| 64-206 | ||||||||||||||||||
| 737 | return; executed 64 times by 1 test: return;Executed by:
| 64 | ||||||||||||||||||
| 738 | - | |||||||||||||||||||
| 739 | // check if socket is connected | - | ||||||||||||||||||
| 740 | if (socket->state() != QAbstractSocket::ConnectedState)
| 0-206 | ||||||||||||||||||
| 741 | return; never executed: return; | 0 | ||||||||||||||||||
| 742 | - | |||||||||||||||||||
| 743 | // check for resendCurrent | - | ||||||||||||||||||
| 744 | if (channels[i].resendCurrent)
| 0-206 | ||||||||||||||||||
| 745 | return; never executed: return; | 0 | ||||||||||||||||||
| 746 | - | |||||||||||||||||||
| 747 | // we do not like authentication stuff | - | ||||||||||||||||||
| 748 | // ### make sure to be OK with this in later releases | - | ||||||||||||||||||
| 749 | if (!channels[i].authenticator.isNull()
| 0-206 | ||||||||||||||||||
| 750 | && (!channels[i].authenticator.user().isEmpty()
| 0-206 | ||||||||||||||||||
| 751 | || !channels[i].authenticator.password().isEmpty()))
| 0-206 | ||||||||||||||||||
| 752 | return; never executed: return; | 0 | ||||||||||||||||||
| 753 | if (!channels[i].proxyAuthenticator.isNull()
| 0-206 | ||||||||||||||||||
| 754 | && (!channels[i].proxyAuthenticator.user().isEmpty()
| 0-206 | ||||||||||||||||||
| 755 | || !channels[i].proxyAuthenticator.password().isEmpty()))
| 0-206 | ||||||||||||||||||
| 756 | return; never executed: return; | 0 | ||||||||||||||||||
| 757 | - | |||||||||||||||||||
| 758 | // must be in ReadingState or WaitingState | - | ||||||||||||||||||
| 759 | if (! (channels[i].state == QHttpNetworkConnectionChannel::WaitingState
| 16-190 | ||||||||||||||||||
| 760 | || channels[i].state == QHttpNetworkConnectionChannel::ReadingState))
| 0-190 | ||||||||||||||||||
| 761 | return; never executed: return; | 0 | ||||||||||||||||||
| 762 | - | |||||||||||||||||||
| 763 | int lengthBefore; | - | ||||||||||||||||||
| 764 | while (!highPriorityQueue.isEmpty()) {
| 62-176 | ||||||||||||||||||
| 765 | lengthBefore = channels[i].alreadyPipelinedRequests.length(); | - | ||||||||||||||||||
| 766 | fillPipeline(highPriorityQueue, channels[i]); | - | ||||||||||||||||||
| 767 | - | |||||||||||||||||||
| 768 | if (channels[i].alreadyPipelinedRequests.length() >= defaultPipelineLength) {
| 30-32 | ||||||||||||||||||
| 769 | channels[i].pipelineFlush(); | - | ||||||||||||||||||
| 770 | return; executed 30 times by 1 test: return;Executed by:
| 30 | ||||||||||||||||||
| 771 | } | - | ||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | if (lengthBefore == channels[i].alreadyPipelinedRequests.length())
| 0-32 | ||||||||||||||||||
| 774 | break; // did not process anything, now do the low prio queue never executed: break; | 0 | ||||||||||||||||||
| 775 | } executed 32 times by 1 test: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 776 | - | |||||||||||||||||||
| 777 | while (!lowPriorityQueue.isEmpty()) {
| 3-351 | ||||||||||||||||||
| 778 | lengthBefore = channels[i].alreadyPipelinedRequests.length(); | - | ||||||||||||||||||
| 779 | fillPipeline(lowPriorityQueue, channels[i]); | - | ||||||||||||||||||
| 780 | - | |||||||||||||||||||
| 781 | if (channels[i].alreadyPipelinedRequests.length() >= defaultPipelineLength) {
| 162-189 | ||||||||||||||||||
| 782 | channels[i].pipelineFlush(); | - | ||||||||||||||||||
| 783 | return; executed 162 times by 2 tests: return;Executed by:
| 162 | ||||||||||||||||||
| 784 | } | - | ||||||||||||||||||
| 785 | - | |||||||||||||||||||
| 786 | if (lengthBefore == channels[i].alreadyPipelinedRequests.length())
| 11-178 | ||||||||||||||||||
| 787 | break; // did not process anything executed 11 times by 1 test: break;Executed by:
| 11 | ||||||||||||||||||
| 788 | } executed 178 times by 2 tests: end of blockExecuted by:
| 178 | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | - | |||||||||||||||||||
| 791 | channels[i].pipelineFlush(); | - | ||||||||||||||||||
| 792 | } executed 14 times by 2 tests: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 793 | - | |||||||||||||||||||
| 794 | // returns true when the processing of a queue has been done | - | ||||||||||||||||||
| 795 | bool QHttpNetworkConnectionPrivate::fillPipeline(QList<HttpMessagePair> &queue, QHttpNetworkConnectionChannel &channel) | - | ||||||||||||||||||
| 796 | { | - | ||||||||||||||||||
| 797 | if (queue.isEmpty())
| 0-413 | ||||||||||||||||||
| 798 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 799 | - | |||||||||||||||||||
| 800 | for (int i = queue.count() - 1; i >= 0; --i) {
| 11-772 | ||||||||||||||||||
| 801 | HttpMessagePair messagePair = queue.at(i); | - | ||||||||||||||||||
| 802 | const QHttpNetworkRequest &request = messagePair.first; | - | ||||||||||||||||||
| 803 | - | |||||||||||||||||||
| 804 | // we currently do not support pipelining if HTTP authentication is used | - | ||||||||||||||||||
| 805 | if (!request.url().userInfo().isEmpty())
| 0-772 | ||||||||||||||||||
| 806 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 807 | - | |||||||||||||||||||
| 808 | // take only GET requests | - | ||||||||||||||||||
| 809 | if (request.operation() != QHttpNetworkRequest::Get)
| 370-402 | ||||||||||||||||||
| 810 | continue; executed 370 times by 1 test: continue;Executed by:
| 370 | ||||||||||||||||||
| 811 | - | |||||||||||||||||||
| 812 | if (!request.isPipeliningAllowed())
| 0-402 | ||||||||||||||||||
| 813 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 814 | - | |||||||||||||||||||
| 815 | // remove it from the queue | - | ||||||||||||||||||
| 816 | queue.takeAt(i); | - | ||||||||||||||||||
| 817 | // we modify the queue we iterate over here, but since we return from the function | - | ||||||||||||||||||
| 818 | // afterwards this is fine. | - | ||||||||||||||||||
| 819 | - | |||||||||||||||||||
| 820 | // actually send it | - | ||||||||||||||||||
| 821 | if (!messagePair.second->d_func()->requestIsPrepared)
| 0-402 | ||||||||||||||||||
| 822 | prepareRequest(messagePair); executed 402 times by 2 tests: prepareRequest(messagePair);Executed by:
| 402 | ||||||||||||||||||
| 823 | channel.pipelineInto(messagePair); | - | ||||||||||||||||||
| 824 | - | |||||||||||||||||||
| 825 | // return false because we processed something and need to process again | - | ||||||||||||||||||
| 826 | return false; executed 402 times by 2 tests: return false;Executed by:
| 402 | ||||||||||||||||||
| 827 | } | - | ||||||||||||||||||
| 828 | - | |||||||||||||||||||
| 829 | // return true, the queue has been processed and not changed | - | ||||||||||||||||||
| 830 | return true; executed 11 times by 1 test: return true;Executed by:
| 11 | ||||||||||||||||||
| 831 | } | - | ||||||||||||||||||
| 832 | - | |||||||||||||||||||
| 833 | - | |||||||||||||||||||
| 834 | QString QHttpNetworkConnectionPrivate::errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket *socket, const QString &extraDetail) | - | ||||||||||||||||||
| 835 | { | - | ||||||||||||||||||
| 836 | QString errorString; | - | ||||||||||||||||||
| 837 | switch (errorCode) { | - | ||||||||||||||||||
| 838 | case QNetworkReply::HostNotFoundError: executed 6 times by 3 tests: case QNetworkReply::HostNotFoundError:Executed by:
| 6 | ||||||||||||||||||
| 839 | if (socket)
| 2-4 | ||||||||||||||||||
| 840 | errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(socket->peerName()); executed 2 times by 1 test: errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(socket->peerName());Executed by:
| 2 | ||||||||||||||||||
| 841 | else | - | ||||||||||||||||||
| 842 | errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(hostName); executed 4 times by 3 tests: errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(hostName);Executed by:
| 4 | ||||||||||||||||||
| 843 | break; executed 6 times by 3 tests: break;Executed by:
| 6 | ||||||||||||||||||
| 844 | case QNetworkReply::ConnectionRefusedError: executed 124 times by 2 tests: case QNetworkReply::ConnectionRefusedError:Executed by:
| 124 | ||||||||||||||||||
| 845 | errorString = QCoreApplication::translate("QHttp", "Connection refused"); | - | ||||||||||||||||||
| 846 | break; executed 124 times by 2 tests: break;Executed by:
| 124 | ||||||||||||||||||
| 847 | case QNetworkReply::RemoteHostClosedError: executed 35 times by 3 tests: case QNetworkReply::RemoteHostClosedError:Executed by:
| 35 | ||||||||||||||||||
| 848 | errorString = QCoreApplication::translate("QHttp", "Connection closed"); | - | ||||||||||||||||||
| 849 | break; executed 35 times by 3 tests: break;Executed by:
| 35 | ||||||||||||||||||
| 850 | case QNetworkReply::TimeoutError: never executed: case QNetworkReply::TimeoutError: | 0 | ||||||||||||||||||
| 851 | errorString = QCoreApplication::translate("QAbstractSocket", "Socket operation timed out"); | - | ||||||||||||||||||
| 852 | break; never executed: break; | 0 | ||||||||||||||||||
| 853 | case QNetworkReply::ProxyAuthenticationRequiredError: executed 9 times by 2 tests: case QNetworkReply::ProxyAuthenticationRequiredError:Executed by:
| 9 | ||||||||||||||||||
| 854 | errorString = QCoreApplication::translate("QHttp", "Proxy requires authentication"); | - | ||||||||||||||||||
| 855 | break; executed 9 times by 2 tests: break;Executed by:
| 9 | ||||||||||||||||||
| 856 | case QNetworkReply::AuthenticationRequiredError: executed 37 times by 2 tests: case QNetworkReply::AuthenticationRequiredError:Executed by:
| 37 | ||||||||||||||||||
| 857 | errorString = QCoreApplication::translate("QHttp", "Host requires authentication"); | - | ||||||||||||||||||
| 858 | break; executed 37 times by 2 tests: break;Executed by:
| 37 | ||||||||||||||||||
| 859 | case QNetworkReply::ProtocolFailure: executed 1 time by 1 test: case QNetworkReply::ProtocolFailure:Executed by:
| 1 | ||||||||||||||||||
| 860 | errorString = QCoreApplication::translate("QHttp", "Data corrupted"); | - | ||||||||||||||||||
| 861 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||
| 862 | case QNetworkReply::ProtocolUnknownError: never executed: case QNetworkReply::ProtocolUnknownError: | 0 | ||||||||||||||||||
| 863 | errorString = QCoreApplication::translate("QHttp", "Unknown protocol specified"); | - | ||||||||||||||||||
| 864 | break; never executed: break; | 0 | ||||||||||||||||||
| 865 | case QNetworkReply::SslHandshakeFailedError: executed 12 times by 3 tests: case QNetworkReply::SslHandshakeFailedError:Executed by:
| 12 | ||||||||||||||||||
| 866 | errorString = QCoreApplication::translate("QHttp", "SSL handshake failed"); | - | ||||||||||||||||||
| 867 | break; executed 12 times by 3 tests: break;Executed by:
| 12 | ||||||||||||||||||
| 868 | case QNetworkReply::TooManyRedirectsError: executed 1 time by 1 test: case QNetworkReply::TooManyRedirectsError:Executed by:
| 1 | ||||||||||||||||||
| 869 | errorString = QCoreApplication::translate("QHttp", "Too many redirects"); | - | ||||||||||||||||||
| 870 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||
| 871 | case QNetworkReply::InsecureRedirectError: never executed: case QNetworkReply::InsecureRedirectError: | 0 | ||||||||||||||||||
| 872 | errorString = QCoreApplication::translate("QHttp", "Insecure redirect"); | - | ||||||||||||||||||
| 873 | break; never executed: break; | 0 | ||||||||||||||||||
| 874 | default: executed 4 times by 2 tests: default:Executed by:
| 4 | ||||||||||||||||||
| 875 | // all other errors are treated as QNetworkReply::UnknownNetworkError | - | ||||||||||||||||||
| 876 | errorString = extraDetail; | - | ||||||||||||||||||
| 877 | break; executed 4 times by 2 tests: break;Executed by:
| 4 | ||||||||||||||||||
| 878 | } | - | ||||||||||||||||||
| 879 | return errorString; executed 229 times by 4 tests: return errorString;Executed by:
| 229 | ||||||||||||||||||
| 880 | } | - | ||||||||||||||||||
| 881 | - | |||||||||||||||||||
| 882 | // this is called from the destructor of QHttpNetworkReply. It is called when | - | ||||||||||||||||||
| 883 | // the reply was finished correctly or when it was aborted. | - | ||||||||||||||||||
| 884 | void QHttpNetworkConnectionPrivate::removeReply(QHttpNetworkReply *reply) | - | ||||||||||||||||||
| 885 | { | - | ||||||||||||||||||
| 886 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
| 887 | - | |||||||||||||||||||
| 888 | // check if the reply is currently being processed or it is pipelined in | - | ||||||||||||||||||
| 889 | for (int i = 0; i < channelCount; ++i) {
| 1537-6232 | ||||||||||||||||||
| 890 | // is the reply associated the currently processing of this channel? | - | ||||||||||||||||||
| 891 | if (channels[i].reply == reply) {
| 25-6207 | ||||||||||||||||||
| 892 | channels[i].reply = 0; | - | ||||||||||||||||||
| 893 | if (channels[i].protocolHandler)
| 0-25 | ||||||||||||||||||
| 894 | channels[i].protocolHandler->setReply(0); executed 25 times by 3 tests: channels[i].protocolHandler->setReply(0);Executed by:
| 25 | ||||||||||||||||||
| 895 | channels[i].request = QHttpNetworkRequest(); | - | ||||||||||||||||||
| 896 | channels[i].resendCurrent = false; | - | ||||||||||||||||||
| 897 | - | |||||||||||||||||||
| 898 | if (!reply->isFinished() && !channels[i].alreadyPipelinedRequests.isEmpty()) {
| 0-19 | ||||||||||||||||||
| 899 | // the reply had to be prematurely removed, e.g. it was not finished | - | ||||||||||||||||||
| 900 | // therefore we have to requeue the already pipelined requests. | - | ||||||||||||||||||
| 901 | channels[i].requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 902 | } never executed: end of block | 0 | ||||||||||||||||||
| 903 | - | |||||||||||||||||||
| 904 | // if HTTP mandates we should close | - | ||||||||||||||||||
| 905 | // or the reply is not finished yet, e.g. it was aborted | - | ||||||||||||||||||
| 906 | // we have to close that connection | - | ||||||||||||||||||
| 907 | if (reply->d_func()->isConnectionCloseEnabled() || !reply->isFinished()) {
| 0-20 | ||||||||||||||||||
| 908 | if (reply->isAborted()) {
| 12-13 | ||||||||||||||||||
| 909 | channels[i].abort(); | - | ||||||||||||||||||
| 910 | } else { executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||
| 911 | channels[i].close(); | - | ||||||||||||||||||
| 912 | } executed 11 times by 3 tests: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 913 | } | - | ||||||||||||||||||
| 914 | - | |||||||||||||||||||
| 915 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 916 | return; executed 24 times by 3 tests: return;Executed by:
| 24 | ||||||||||||||||||
| 917 | } | - | ||||||||||||||||||
| 918 | - | |||||||||||||||||||
| 919 | // is the reply inside the pipeline of this channel already? | - | ||||||||||||||||||
| 920 | for (int j = 0; j < channels[i].alreadyPipelinedRequests.length(); j++) {
| 105-6207 | ||||||||||||||||||
| 921 | if (channels[i].alreadyPipelinedRequests.at(j).second == reply) {
| 0-105 | ||||||||||||||||||
| 922 | // Remove that HttpMessagePair | - | ||||||||||||||||||
| 923 | channels[i].alreadyPipelinedRequests.removeAt(j); | - | ||||||||||||||||||
| 924 | - | |||||||||||||||||||
| 925 | channels[i].requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 926 | - | |||||||||||||||||||
| 927 | // Since some requests had already been pipelined, but we removed | - | ||||||||||||||||||
| 928 | // one and re-queued the others | - | ||||||||||||||||||
| 929 | // we must force a connection close after the request that is | - | ||||||||||||||||||
| 930 | // currently in processing has been finished. | - | ||||||||||||||||||
| 931 | if (channels[i].reply)
| 0 | ||||||||||||||||||
| 932 | channels[i].reply->d_func()->forceConnectionCloseEnabled = true; never executed: channels[i].reply->d_func()->forceConnectionCloseEnabled = true; | 0 | ||||||||||||||||||
| 933 | - | |||||||||||||||||||
| 934 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 935 | return; never executed: return; | 0 | ||||||||||||||||||
| 936 | } | - | ||||||||||||||||||
| 937 | } executed 105 times by 1 test: end of blockExecuted by:
| 105 | ||||||||||||||||||
| 938 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 939 | // is the reply inside the SPDY pipeline of this channel already? | - | ||||||||||||||||||
| 940 | QMultiMap<int, HttpMessagePair>::iterator it = channels[i].spdyRequestsToSend.begin(); | - | ||||||||||||||||||
| 941 | QMultiMap<int, HttpMessagePair>::iterator end = channels[i].spdyRequestsToSend.end(); | - | ||||||||||||||||||
| 942 | for (; it != end; ++it) {
| 5-6202 | ||||||||||||||||||
| 943 | if (it.value().second == reply) {
| 0-5 | ||||||||||||||||||
| 944 | channels[i].spdyRequestsToSend.remove(it.key()); | - | ||||||||||||||||||
| 945 | - | |||||||||||||||||||
| 946 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 947 | return; executed 5 times by 1 test: return;Executed by:
| 5 | ||||||||||||||||||
| 948 | } | - | ||||||||||||||||||
| 949 | } never executed: end of block | 0 | ||||||||||||||||||
| 950 | #endif | - | ||||||||||||||||||
| 951 | } executed 6202 times by 7 tests: end of blockExecuted by:
| 6202 | ||||||||||||||||||
| 952 | // remove from the high priority queue | - | ||||||||||||||||||
| 953 | if (!highPriorityQueue.isEmpty()) {
| 0-1537 | ||||||||||||||||||
| 954 | for (int j = highPriorityQueue.count() - 1; j >= 0; --j) {
| 0 | ||||||||||||||||||
| 955 | HttpMessagePair messagePair = highPriorityQueue.at(j); | - | ||||||||||||||||||
| 956 | if (messagePair.second == reply) {
| 0 | ||||||||||||||||||
| 957 | highPriorityQueue.removeAt(j); | - | ||||||||||||||||||
| 958 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 959 | return; never executed: return; | 0 | ||||||||||||||||||
| 960 | } | - | ||||||||||||||||||
| 961 | } never executed: end of block | 0 | ||||||||||||||||||
| 962 | } never executed: end of block | 0 | ||||||||||||||||||
| 963 | // remove from the low priority queue | - | ||||||||||||||||||
| 964 | if (!lowPriorityQueue.isEmpty()) {
| 90-1447 | ||||||||||||||||||
| 965 | for (int j = lowPriorityQueue.count() - 1; j >= 0; --j) {
| 83-437 | ||||||||||||||||||
| 966 | HttpMessagePair messagePair = lowPriorityQueue.at(j); | - | ||||||||||||||||||
| 967 | if (messagePair.second == reply) {
| 7-430 | ||||||||||||||||||
| 968 | lowPriorityQueue.removeAt(j); | - | ||||||||||||||||||
| 969 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 970 | return; executed 7 times by 1 test: return;Executed by:
| 7 | ||||||||||||||||||
| 971 | } | - | ||||||||||||||||||
| 972 | } executed 430 times by 2 tests: end of blockExecuted by:
| 430 | ||||||||||||||||||
| 973 | } executed 83 times by 2 tests: end of blockExecuted by:
| 83 | ||||||||||||||||||
| 974 | } executed 1530 times by 7 tests: end of blockExecuted by:
| 1530 | ||||||||||||||||||
| 975 | - | |||||||||||||||||||
| 976 | - | |||||||||||||||||||
| 977 | - | |||||||||||||||||||
| 978 | // This function must be called from the event loop. The only | - | ||||||||||||||||||
| 979 | // exception is documented in QHttpNetworkConnectionPrivate::queueRequest | - | ||||||||||||||||||
| 980 | // although it is called _q_startNextRequest, it will actually start multiple requests when possible | - | ||||||||||||||||||
| 981 | void QHttpNetworkConnectionPrivate::_q_startNextRequest() | - | ||||||||||||||||||
| 982 | { | - | ||||||||||||||||||
| 983 | // If there is no network layer state decided we should not start any new requests. | - | ||||||||||||||||||
| 984 | if (networkLayerState == Unknown || networkLayerState == HostLookupPending || networkLayerState == IPv4or6)
| 0-5341 | ||||||||||||||||||
| 985 | return; executed 5 times by 3 tests: return;Executed by:
| 5 | ||||||||||||||||||
| 986 | - | |||||||||||||||||||
| 987 | // If the QHttpNetworkConnection is currently paused then bail out immediately | - | ||||||||||||||||||
| 988 | if (state == PausedState)
| 0-5339 | ||||||||||||||||||
| 989 | return; never executed: return; | 0 | ||||||||||||||||||
| 990 | - | |||||||||||||||||||
| 991 | //resend the necessary ones. | - | ||||||||||||||||||
| 992 | for (int i = 0; i < channelCount; ++i) {
| 5339-25349 | ||||||||||||||||||
| 993 | if (channels[i].resendCurrent && (channels[i].state != QHttpNetworkConnectionChannel::ClosingState)) {
| 0-25108 | ||||||||||||||||||
| 994 | channels[i].resendCurrent = false; | - | ||||||||||||||||||
| 995 | - | |||||||||||||||||||
| 996 | // if this is not possible, error will be emitted and connection terminated | - | ||||||||||||||||||
| 997 | if (!channels[i].resetUploadData())
| 9-232 | ||||||||||||||||||
| 998 | continue; executed 9 times by 2 tests: continue;Executed by:
| 9 | ||||||||||||||||||
| 999 | channels[i].sendRequest(); | - | ||||||||||||||||||
| 1000 | } executed 232 times by 2 tests: end of blockExecuted by:
| 232 | ||||||||||||||||||
| 1001 | } executed 25340 times by 8 tests: end of blockExecuted by:
| 25340 | ||||||||||||||||||
| 1002 | - | |||||||||||||||||||
| 1003 | // dequeue new ones | - | ||||||||||||||||||
| 1004 | - | |||||||||||||||||||
| 1005 | switch (connectionType) { | - | ||||||||||||||||||
| 1006 | case QHttpNetworkConnection::ConnectionTypeHTTP: { executed 5214 times by 8 tests: case QHttpNetworkConnection::ConnectionTypeHTTP:Executed by:
| 5214 | ||||||||||||||||||
| 1007 | // return fast if there is nothing to do | - | ||||||||||||||||||
| 1008 | if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty())
| 352-4862 | ||||||||||||||||||
| 1009 | return; executed 2551 times by 7 tests: return;Executed by:
| 2551 | ||||||||||||||||||
| 1010 | - | |||||||||||||||||||
| 1011 | // try to get a free AND connected socket | - | ||||||||||||||||||
| 1012 | for (int i = 0; i < channelCount; ++i) {
| 2663-10056 | ||||||||||||||||||
| 1013 | if (channels[i].socket) {
| 3635-6421 | ||||||||||||||||||
| 1014 | if (!channels[i].reply && !channels[i].isSocketBusy() && channels[i].socket->state() == QAbstractSocket::ConnectedState) {
| 56-3587 | ||||||||||||||||||
| 1015 | if (dequeueRequest(channels[i].socket))
| 13-461 | ||||||||||||||||||
| 1016 | channels[i].sendRequest(); executed 461 times by 4 tests: channels[i].sendRequest();Executed by:
| 461 | ||||||||||||||||||
| 1017 | } executed 474 times by 4 tests: end of blockExecuted by:
| 474 | ||||||||||||||||||
| 1018 | } executed 6421 times by 4 tests: end of blockExecuted by:
| 6421 | ||||||||||||||||||
| 1019 | } executed 10056 times by 7 tests: end of blockExecuted by:
| 10056 | ||||||||||||||||||
| 1020 | break; executed 2663 times by 7 tests: break;Executed by:
| 2663 | ||||||||||||||||||
| 1021 | } | - | ||||||||||||||||||
| 1022 | case QHttpNetworkConnection::ConnectionTypeSPDY: { executed 125 times by 1 test: case QHttpNetworkConnection::ConnectionTypeSPDY:Executed by:
| 125 | ||||||||||||||||||
| 1023 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1024 | if (channels[0].spdyRequestsToSend.isEmpty())
| 6-119 | ||||||||||||||||||
| 1025 | return; executed 6 times by 1 test: return;Executed by:
| 6 | ||||||||||||||||||
| 1026 | - | |||||||||||||||||||
| 1027 | if (networkLayerState == IPv4)
| 0-119 | ||||||||||||||||||
| 1028 | channels[0].networkLayerPreference = QAbstractSocket::IPv4Protocol; executed 119 times by 1 test: channels[0].networkLayerPreference = QAbstractSocket::IPv4Protocol;Executed by:
| 119 | ||||||||||||||||||
| 1029 | else if (networkLayerState == IPv6)
| 0 | ||||||||||||||||||
| 1030 | channels[0].networkLayerPreference = QAbstractSocket::IPv6Protocol; never executed: channels[0].networkLayerPreference = QAbstractSocket::IPv6Protocol; | 0 | ||||||||||||||||||
| 1031 | channels[0].ensureConnection(); | - | ||||||||||||||||||
| 1032 | if (channels[0].socket && channels[0].socket->state() == QAbstractSocket::ConnectedState
| 0-119 | ||||||||||||||||||
| 1033 | && !channels[0].pendingEncrypt)
| 0-107 | ||||||||||||||||||
| 1034 | channels[0].sendRequest(); executed 107 times by 1 test: channels[0].sendRequest();Executed by:
| 107 | ||||||||||||||||||
| 1035 | #endif // QT_NO_SSL | - | ||||||||||||||||||
| 1036 | break; executed 119 times by 1 test: break;Executed by:
| 119 | ||||||||||||||||||
| 1037 | } | - | ||||||||||||||||||
| 1038 | } | - | ||||||||||||||||||
| 1039 | - | |||||||||||||||||||
| 1040 | // try to push more into all sockets | - | ||||||||||||||||||
| 1041 | // ### FIXME we should move this to the beginning of the function | - | ||||||||||||||||||
| 1042 | // as soon as QtWebkit is properly using the pipelining | - | ||||||||||||||||||
| 1043 | // (e.g. not for XMLHttpRequest or the first page load) | - | ||||||||||||||||||
| 1044 | // ### FIXME we should also divide the requests more even | - | ||||||||||||||||||
| 1045 | // on the connected sockets | - | ||||||||||||||||||
| 1046 | //tryToFillPipeline(socket); | - | ||||||||||||||||||
| 1047 | // return fast if there is nothing to pipeline | - | ||||||||||||||||||
| 1048 | if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty())
| 192-2431 | ||||||||||||||||||
| 1049 | return; executed 192 times by 4 tests: return;Executed by:
| 192 | ||||||||||||||||||
| 1050 | for (int i = 0; i < channelCount; i++)
| 2590-9631 | ||||||||||||||||||
| 1051 | if (channels[i].socket && channels[i].socket->state() == QAbstractSocket::ConnectedState)
| 2418-6303 | ||||||||||||||||||
| 1052 | fillPipeline(channels[i].socket); executed 3885 times by 2 tests: fillPipeline(channels[i].socket);Executed by:
| 3885 | ||||||||||||||||||
| 1053 | - | |||||||||||||||||||
| 1054 | // If there is not already any connected channels we need to connect a new one. | - | ||||||||||||||||||
| 1055 | // We do not pair the channel with the request until we know if it is | - | ||||||||||||||||||
| 1056 | // connected or not. This is to reuse connected channels before we connect new once. | - | ||||||||||||||||||
| 1057 | int queuedRequests = highPriorityQueue.count() + lowPriorityQueue.count(); | - | ||||||||||||||||||
| 1058 | - | |||||||||||||||||||
| 1059 | // in case we have in-flight preconnect requests and normal requests, | - | ||||||||||||||||||
| 1060 | // we only need one socket for each (preconnect, normal request) pair | - | ||||||||||||||||||
| 1061 | int neededOpenChannels = queuedRequests; | - | ||||||||||||||||||
| 1062 | if (preConnectRequests > 0) {
| 0-2590 | ||||||||||||||||||
| 1063 | int normalRequests = queuedRequests - preConnectRequests; | - | ||||||||||||||||||
| 1064 | neededOpenChannels = qMax(normalRequests, preConnectRequests); | - | ||||||||||||||||||
| 1065 | } never executed: end of block | 0 | ||||||||||||||||||
| 1066 | for (int i = 0; i < channelCount && neededOpenChannels > 0; ++i) {
| 509-7244 | ||||||||||||||||||
| 1067 | bool connectChannel = false; | - | ||||||||||||||||||
| 1068 | if (channels[i].socket) {
| 497-6238 | ||||||||||||||||||
| 1069 | if ((channels[i].socket->state() == QAbstractSocket::ConnectingState)
| 2332-3906 | ||||||||||||||||||
| 1070 | || (channels[i].socket->state() == QAbstractSocket::HostLookupState)
| 0-3906 | ||||||||||||||||||
| 1071 | || channels[i].pendingEncrypt) // pendingEncrypt == "EncryptingState"
| 23-3883 | ||||||||||||||||||
| 1072 | neededOpenChannels--; executed 2355 times by 2 tests: neededOpenChannels--;Executed by:
| 2355 | ||||||||||||||||||
| 1073 | - | |||||||||||||||||||
| 1074 | if (neededOpenChannels <= 0)
| 122-6116 | ||||||||||||||||||
| 1075 | break; executed 122 times by 2 tests: break;Executed by:
| 122 | ||||||||||||||||||
| 1076 | if (!channels[i].reply && !channels[i].isSocketBusy() && (channels[i].socket->state() == QAbstractSocket::UnconnectedState))
| 0-3909 | ||||||||||||||||||
| 1077 | connectChannel = true; executed 47 times by 2 tests: connectChannel = true;Executed by:
| 47 | ||||||||||||||||||
| 1078 | } else { // not previously used channel executed 6116 times by 2 tests: end of blockExecuted by:
| 6116 | ||||||||||||||||||
| 1079 | connectChannel = true; | - | ||||||||||||||||||
| 1080 | } executed 497 times by 7 tests: end of blockExecuted by:
| 497 | ||||||||||||||||||
| 1081 | - | |||||||||||||||||||
| 1082 | if (connectChannel) {
| 544-6069 | ||||||||||||||||||
| 1083 | if (networkLayerState == IPv4)
| 1-543 | ||||||||||||||||||
| 1084 | channels[i].networkLayerPreference = QAbstractSocket::IPv4Protocol; executed 543 times by 7 tests: channels[i].networkLayerPreference = QAbstractSocket::IPv4Protocol;Executed by:
| 543 | ||||||||||||||||||
| 1085 | else if (networkLayerState == IPv6)
| 0-1 | ||||||||||||||||||
| 1086 | channels[i].networkLayerPreference = QAbstractSocket::IPv6Protocol; executed 1 time by 1 test: channels[i].networkLayerPreference = QAbstractSocket::IPv6Protocol;Executed by:
| 1 | ||||||||||||||||||
| 1087 | channels[i].ensureConnection(); | - | ||||||||||||||||||
| 1088 | neededOpenChannels--; | - | ||||||||||||||||||
| 1089 | } executed 544 times by 7 tests: end of blockExecuted by:
| 544 | ||||||||||||||||||
| 1090 | } executed 6613 times by 7 tests: end of blockExecuted by:
| 6613 | ||||||||||||||||||
| 1091 | } executed 2590 times by 7 tests: end of blockExecuted by:
| 2590 | ||||||||||||||||||
| 1092 | - | |||||||||||||||||||
| 1093 | - | |||||||||||||||||||
| 1094 | void QHttpNetworkConnectionPrivate::readMoreLater(QHttpNetworkReply *reply) | - | ||||||||||||||||||
| 1095 | { | - | ||||||||||||||||||
| 1096 | for (int i = 0 ; i < channelCount; ++i) {
| 16-289 | ||||||||||||||||||
| 1097 | if (channels[i].reply == reply) {
| 96-193 | ||||||||||||||||||
| 1098 | // emulate a readyRead() from the socket | - | ||||||||||||||||||
| 1099 | QMetaObject::invokeMethod(&channels[i], "_q_readyRead", Qt::QueuedConnection); | - | ||||||||||||||||||
| 1100 | return; executed 193 times by 1 test: return;Executed by:
| 193 | ||||||||||||||||||
| 1101 | } | - | ||||||||||||||||||
| 1102 | } executed 96 times by 2 tests: end of blockExecuted by:
| 96 | ||||||||||||||||||
| 1103 | } executed 16 times by 2 tests: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 1104 | - | |||||||||||||||||||
| 1105 | - | |||||||||||||||||||
| 1106 | - | |||||||||||||||||||
| 1107 | // The first time we start the connection is used we do not know if we | - | ||||||||||||||||||
| 1108 | // should use IPv4 or IPv6. So we start a hostlookup to figure this out. | - | ||||||||||||||||||
| 1109 | // Later when we do the connection the socket will not need to do another | - | ||||||||||||||||||
| 1110 | // lookup as then the hostinfo will already be in the cache. | - | ||||||||||||||||||
| 1111 | void QHttpNetworkConnectionPrivate::startHostInfoLookup() | - | ||||||||||||||||||
| 1112 | { | - | ||||||||||||||||||
| 1113 | networkLayerState = HostLookupPending; | - | ||||||||||||||||||
| 1114 | - | |||||||||||||||||||
| 1115 | // check if we already now can decide if this is IPv4 or IPv6 | - | ||||||||||||||||||
| 1116 | QString lookupHost = hostName; | - | ||||||||||||||||||
| 1117 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 1118 | if (networkProxy.capabilities() & QNetworkProxy::HostNameLookupCapability) {
| 44-539 | ||||||||||||||||||
| 1119 | lookupHost = networkProxy.hostName(); | - | ||||||||||||||||||
| 1120 | } else if (channels[0].proxy.capabilities() & QNetworkProxy::HostNameLookupCapability) { executed 44 times by 1 test: end of blockExecuted by:
| 44-481 | ||||||||||||||||||
| 1121 | lookupHost = channels[0].proxy.hostName(); | - | ||||||||||||||||||
| 1122 | } executed 58 times by 2 tests: end of blockExecuted by:
| 58 | ||||||||||||||||||
| 1123 | #endif | - | ||||||||||||||||||
| 1124 | QHostAddress temp; | - | ||||||||||||||||||
| 1125 | if (temp.setAddress(lookupHost)) {
| 108-475 | ||||||||||||||||||
| 1126 | const QAbstractSocket::NetworkLayerProtocol protocol = temp.protocol(); | - | ||||||||||||||||||
| 1127 | if (protocol == QAbstractSocket::IPv4Protocol) {
| 1-107 | ||||||||||||||||||
| 1128 | networkLayerState = QHttpNetworkConnectionPrivate::IPv4; | - | ||||||||||||||||||
| 1129 | QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 1130 | return; executed 107 times by 5 tests: return;Executed by:
| 107 | ||||||||||||||||||
| 1131 | } else if (protocol == QAbstractSocket::IPv6Protocol) {
| 0-1 | ||||||||||||||||||
| 1132 | networkLayerState = QHttpNetworkConnectionPrivate::IPv6; | - | ||||||||||||||||||
| 1133 | QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 1134 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 1135 | } | - | ||||||||||||||||||
| 1136 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1137 | int hostLookupId; | - | ||||||||||||||||||
| 1138 | bool immediateResultValid = false; | - | ||||||||||||||||||
| 1139 | QHostInfo hostInfo = qt_qhostinfo_lookup(lookupHost, | - | ||||||||||||||||||
| 1140 | this->q_func(), | - | ||||||||||||||||||
| 1141 | SLOT(_q_hostLookupFinished(QHostInfo)), | - | ||||||||||||||||||
| 1142 | &immediateResultValid, | - | ||||||||||||||||||
| 1143 | &hostLookupId); | - | ||||||||||||||||||
| 1144 | if (immediateResultValid) {
| 15-460 | ||||||||||||||||||
| 1145 | _q_hostLookupFinished(hostInfo); | - | ||||||||||||||||||
| 1146 | } executed 460 times by 6 tests: end of blockExecuted by:
| 460 | ||||||||||||||||||
| 1147 | } executed 475 times by 7 tests: end of blockExecuted by:
| 475 | ||||||||||||||||||
| 1148 | } | - | ||||||||||||||||||
| 1149 | - | |||||||||||||||||||
| 1150 | - | |||||||||||||||||||
| 1151 | void QHttpNetworkConnectionPrivate::_q_hostLookupFinished(const QHostInfo &info) | - | ||||||||||||||||||
| 1152 | { | - | ||||||||||||||||||
| 1153 | bool bIpv4 = false; | - | ||||||||||||||||||
| 1154 | bool bIpv6 = false; | - | ||||||||||||||||||
| 1155 | bool foundAddress = false; | - | ||||||||||||||||||
| 1156 | if (networkLayerState == IPv4 || networkLayerState == IPv6 || networkLayerState == IPv4or6)
| 0-475 | ||||||||||||||||||
| 1157 | return; never executed: return; | 0 | ||||||||||||||||||
| 1158 | - | |||||||||||||||||||
| 1159 | const auto addresses = info.addresses(); | - | ||||||||||||||||||
| 1160 | for (const QHostAddress &address : addresses) { | - | ||||||||||||||||||
| 1161 | const QAbstractSocket::NetworkLayerProtocol protocol = address.protocol(); | - | ||||||||||||||||||
| 1162 | if (protocol == QAbstractSocket::IPv4Protocol) {
| 130-475 | ||||||||||||||||||
| 1163 | if (!foundAddress) {
| 126-349 | ||||||||||||||||||
| 1164 | foundAddress = true; | - | ||||||||||||||||||
| 1165 | delayIpv4 = false; | - | ||||||||||||||||||
| 1166 | } executed 349 times by 6 tests: end of blockExecuted by:
| 349 | ||||||||||||||||||
| 1167 | bIpv4 = true; | - | ||||||||||||||||||
| 1168 | } else if (protocol == QAbstractSocket::IPv6Protocol) { executed 475 times by 7 tests: end of blockExecuted by:
| 0-475 | ||||||||||||||||||
| 1169 | if (!foundAddress) {
| 8-122 | ||||||||||||||||||
| 1170 | foundAddress = true; | - | ||||||||||||||||||
| 1171 | delayIpv4 = true; | - | ||||||||||||||||||
| 1172 | } executed 122 times by 2 tests: end of blockExecuted by:
| 122 | ||||||||||||||||||
| 1173 | bIpv6 = true; | - | ||||||||||||||||||
| 1174 | } executed 130 times by 3 tests: end of blockExecuted by:
| 130 | ||||||||||||||||||
| 1175 | } executed 605 times by 7 tests: end of blockExecuted by:
| 605 | ||||||||||||||||||
| 1176 | - | |||||||||||||||||||
| 1177 | if (bIpv4 && bIpv6)
| 4-471 | ||||||||||||||||||
| 1178 | startNetworkLayerStateLookup(); executed 126 times by 3 tests: startNetworkLayerStateLookup();Executed by:
| 126 | ||||||||||||||||||
| 1179 | else if (bIpv4) {
| 4-345 | ||||||||||||||||||
| 1180 | networkLayerState = QHttpNetworkConnectionPrivate::IPv4; | - | ||||||||||||||||||
| 1181 | QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 1182 | } else if (bIpv6) { executed 345 times by 5 tests: end of blockExecuted by:
| 0-345 | ||||||||||||||||||
| 1183 | networkLayerState = QHttpNetworkConnectionPrivate::IPv6; | - | ||||||||||||||||||
| 1184 | QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 1185 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1186 | if (dequeueRequest(channels[0].socket)) {
| 2 | ||||||||||||||||||
| 1187 | emitReplyError(channels[0].socket, channels[0].reply, QNetworkReply::HostNotFoundError); | - | ||||||||||||||||||
| 1188 | networkLayerState = QHttpNetworkConnectionPrivate::Unknown; | - | ||||||||||||||||||
| 1189 | } executed 2 times by 2 tests: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1190 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1191 | else if (connectionType == QHttpNetworkConnection::ConnectionTypeSPDY) {
| 0-2 | ||||||||||||||||||
| 1192 | for (const HttpMessagePair &spdyPair : qAsConst(channels[0].spdyRequestsToSend)) { | - | ||||||||||||||||||
| 1193 | // emit error for all replies | - | ||||||||||||||||||
| 1194 | QHttpNetworkReply *currentReply = spdyPair.second; | - | ||||||||||||||||||
| 1195 | Q_ASSERT(currentReply); | - | ||||||||||||||||||
| 1196 | emitReplyError(channels[0].socket, currentReply, QNetworkReply::HostNotFoundError); | - | ||||||||||||||||||
| 1197 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1198 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1199 | #endif // QT_NO_SSL | - | ||||||||||||||||||
| 1200 | else { | - | ||||||||||||||||||
| 1201 | // Should not happen | - | ||||||||||||||||||
| 1202 | qWarning("QHttpNetworkConnectionPrivate::_q_hostLookupFinished could not de-queue request"); | - | ||||||||||||||||||
| 1203 | networkLayerState = QHttpNetworkConnectionPrivate::Unknown; | - | ||||||||||||||||||
| 1204 | } never executed: end of block | 0 | ||||||||||||||||||
| 1205 | } | - | ||||||||||||||||||
| 1206 | } | - | ||||||||||||||||||
| 1207 | - | |||||||||||||||||||
| 1208 | - | |||||||||||||||||||
| 1209 | // This will be used if the host lookup found both and Ipv4 and | - | ||||||||||||||||||
| 1210 | // Ipv6 address. Then we will start up two connections and pick | - | ||||||||||||||||||
| 1211 | // the network layer of the one that finish first. The second | - | ||||||||||||||||||
| 1212 | // connection will then be disconnected. | - | ||||||||||||||||||
| 1213 | void QHttpNetworkConnectionPrivate::startNetworkLayerStateLookup() | - | ||||||||||||||||||
| 1214 | { | - | ||||||||||||||||||
| 1215 | if (channelCount > 1) {
| 0-126 | ||||||||||||||||||
| 1216 | // At this time all channels should be unconnected. | - | ||||||||||||||||||
| 1217 | Q_ASSERT(!channels[0].isSocketBusy()); | - | ||||||||||||||||||
| 1218 | Q_ASSERT(!channels[1].isSocketBusy()); | - | ||||||||||||||||||
| 1219 | - | |||||||||||||||||||
| 1220 | networkLayerState = IPv4or6; | - | ||||||||||||||||||
| 1221 | - | |||||||||||||||||||
| 1222 | channels[0].networkLayerPreference = QAbstractSocket::IPv4Protocol; | - | ||||||||||||||||||
| 1223 | channels[1].networkLayerPreference = QAbstractSocket::IPv6Protocol; | - | ||||||||||||||||||
| 1224 | - | |||||||||||||||||||
| 1225 | int timeout = 300; | - | ||||||||||||||||||
| 1226 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 1227 | if (networkSession) {
| 0-126 | ||||||||||||||||||
| 1228 | const QNetworkConfiguration::BearerType bearerType = networkSession->configuration().bearerType(); | - | ||||||||||||||||||
| 1229 | if (bearerType == QNetworkConfiguration::Bearer2G)
| 0-126 | ||||||||||||||||||
| 1230 | timeout = 800; never executed: timeout = 800; | 0 | ||||||||||||||||||
| 1231 | else if (bearerType == QNetworkConfiguration::BearerCDMA2000)
| 0-126 | ||||||||||||||||||
| 1232 | timeout = 500; never executed: timeout = 500; | 0 | ||||||||||||||||||
| 1233 | else if (bearerType == QNetworkConfiguration::BearerWCDMA)
| 0-126 | ||||||||||||||||||
| 1234 | timeout = 500; never executed: timeout = 500; | 0 | ||||||||||||||||||
| 1235 | else if (bearerType == QNetworkConfiguration::BearerHSPA)
| 0-126 | ||||||||||||||||||
| 1236 | timeout = 400; never executed: timeout = 400; | 0 | ||||||||||||||||||
| 1237 | } executed 126 times by 3 tests: end of blockExecuted by:
| 126 | ||||||||||||||||||
| 1238 | #endif | - | ||||||||||||||||||
| 1239 | delayedConnectionTimer.start(timeout); | - | ||||||||||||||||||
| 1240 | if (delayIpv4)
| 4-122 | ||||||||||||||||||
| 1241 | channels[1].ensureConnection(); executed 122 times by 2 tests: channels[1].ensureConnection();Executed by:
| 122 | ||||||||||||||||||
| 1242 | else | - | ||||||||||||||||||
| 1243 | channels[0].ensureConnection(); executed 4 times by 2 tests: channels[0].ensureConnection();Executed by:
| 4 | ||||||||||||||||||
| 1244 | } else { | - | ||||||||||||||||||
| 1245 | networkLayerState = IPv4or6; | - | ||||||||||||||||||
| 1246 | channels[0].networkLayerPreference = QAbstractSocket::AnyIPProtocol; | - | ||||||||||||||||||
| 1247 | channels[0].ensureConnection(); | - | ||||||||||||||||||
| 1248 | } never executed: end of block | 0 | ||||||||||||||||||
| 1249 | } | - | ||||||||||||||||||
| 1250 | - | |||||||||||||||||||
| 1251 | void QHttpNetworkConnectionPrivate::networkLayerDetected(QAbstractSocket::NetworkLayerProtocol protocol) | - | ||||||||||||||||||
| 1252 | { | - | ||||||||||||||||||
| 1253 | for (int i = 0 ; i < channelCount; ++i) {
| 124-744 | ||||||||||||||||||
| 1254 | if ((channels[i].networkLayerPreference != protocol) && (channels[i].state == QHttpNetworkConnectionChannel::ConnectingState)) {
| 0-620 | ||||||||||||||||||
| 1255 | channels[i].close(); | - | ||||||||||||||||||
| 1256 | } never executed: end of block | 0 | ||||||||||||||||||
| 1257 | } executed 744 times by 2 tests: end of blockExecuted by:
| 744 | ||||||||||||||||||
| 1258 | } executed 124 times by 2 tests: end of blockExecuted by:
| 124 | ||||||||||||||||||
| 1259 | - | |||||||||||||||||||
| 1260 | void QHttpNetworkConnectionPrivate::_q_connectDelayedChannel() | - | ||||||||||||||||||
| 1261 | { | - | ||||||||||||||||||
| 1262 | if (delayIpv4)
| 0 | ||||||||||||||||||
| 1263 | channels[0].ensureConnection(); never executed: channels[0].ensureConnection(); | 0 | ||||||||||||||||||
| 1264 | else | - | ||||||||||||||||||
| 1265 | channels[1].ensureConnection(); never executed: channels[1].ensureConnection(); | 0 | ||||||||||||||||||
| 1266 | } | - | ||||||||||||||||||
| 1267 | - | |||||||||||||||||||
| 1268 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 1269 | QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, | - | ||||||||||||||||||
| 1270 | QHttpNetworkConnection::ConnectionType connectionType, | - | ||||||||||||||||||
| 1271 | QObject *parent, QSharedPointer<QNetworkSession> networkSession) | - | ||||||||||||||||||
| 1272 | : QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt, connectionType)), parent) | - | ||||||||||||||||||
| 1273 | { | - | ||||||||||||||||||
| 1274 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1275 | d->networkSession = qMove(networkSession); | - | ||||||||||||||||||
| 1276 | d->init(); | - | ||||||||||||||||||
| 1277 | } executed 575 times by 8 tests: end of blockExecuted by:
| 575 | ||||||||||||||||||
| 1278 | - | |||||||||||||||||||
| 1279 | QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QString &hostName, | - | ||||||||||||||||||
| 1280 | quint16 port, bool encrypt, QObject *parent, | - | ||||||||||||||||||
| 1281 | QSharedPointer<QNetworkSession> networkSession, | - | ||||||||||||||||||
| 1282 | QHttpNetworkConnection::ConnectionType connectionType) | - | ||||||||||||||||||
| 1283 | : QObject(*(new QHttpNetworkConnectionPrivate(connectionCount, hostName, port, encrypt, | - | ||||||||||||||||||
| 1284 | connectionType)), parent) | - | ||||||||||||||||||
| 1285 | { | - | ||||||||||||||||||
| 1286 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1287 | d->networkSession = qMove(networkSession); | - | ||||||||||||||||||
| 1288 | d->init(); | - | ||||||||||||||||||
| 1289 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 1290 | #else | - | ||||||||||||||||||
| 1291 | QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, | - | ||||||||||||||||||
| 1292 | QHttpNetworkConnection::ConnectionType connectionType, QObject *parent) | - | ||||||||||||||||||
| 1293 | : QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt , connectionType)), parent) | - | ||||||||||||||||||
| 1294 | { | - | ||||||||||||||||||
| 1295 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1296 | d->init(); | - | ||||||||||||||||||
| 1297 | } | - | ||||||||||||||||||
| 1298 | - | |||||||||||||||||||
| 1299 | QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QString &hostName, | - | ||||||||||||||||||
| 1300 | quint16 port, bool encrypt, QObject *parent, | - | ||||||||||||||||||
| 1301 | QHttpNetworkConnection::ConnectionType connectionType) | - | ||||||||||||||||||
| 1302 | : QObject(*(new QHttpNetworkConnectionPrivate(connectionCount, hostName, port, encrypt, | - | ||||||||||||||||||
| 1303 | connectionType)), parent) | - | ||||||||||||||||||
| 1304 | { | - | ||||||||||||||||||
| 1305 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1306 | d->init(); | - | ||||||||||||||||||
| 1307 | } | - | ||||||||||||||||||
| 1308 | #endif | - | ||||||||||||||||||
| 1309 | - | |||||||||||||||||||
| 1310 | QHttpNetworkConnection::~QHttpNetworkConnection() | - | ||||||||||||||||||
| 1311 | { | - | ||||||||||||||||||
| 1312 | } | - | ||||||||||||||||||
| 1313 | - | |||||||||||||||||||
| 1314 | QString QHttpNetworkConnection::hostName() const | - | ||||||||||||||||||
| 1315 | { | - | ||||||||||||||||||
| 1316 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||
| 1317 | return d->hostName; executed 22 times by 1 test: return d->hostName;Executed by:
| 22 | ||||||||||||||||||
| 1318 | } | - | ||||||||||||||||||
| 1319 | - | |||||||||||||||||||
| 1320 | quint16 QHttpNetworkConnection::port() const | - | ||||||||||||||||||
| 1321 | { | - | ||||||||||||||||||
| 1322 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||
| 1323 | return d->port; executed 22 times by 1 test: return d->port;Executed by:
| 22 | ||||||||||||||||||
| 1324 | } | - | ||||||||||||||||||
| 1325 | - | |||||||||||||||||||
| 1326 | QHttpNetworkReply* QHttpNetworkConnection::sendRequest(const QHttpNetworkRequest &request) | - | ||||||||||||||||||
| 1327 | { | - | ||||||||||||||||||
| 1328 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1329 | return d->queueRequest(request); executed 1646 times by 8 tests: return d->queueRequest(request);Executed by:
| 1646 | ||||||||||||||||||
| 1330 | } | - | ||||||||||||||||||
| 1331 | - | |||||||||||||||||||
| 1332 | bool QHttpNetworkConnection::isSsl() const | - | ||||||||||||||||||
| 1333 | { | - | ||||||||||||||||||
| 1334 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||
| 1335 | return d->encrypt; executed 22 times by 1 test: return d->encrypt;Executed by:
| 22 | ||||||||||||||||||
| 1336 | } | - | ||||||||||||||||||
| 1337 | - | |||||||||||||||||||
| 1338 | QHttpNetworkConnectionChannel *QHttpNetworkConnection::channels() const | - | ||||||||||||||||||
| 1339 | { | - | ||||||||||||||||||
| 1340 | return d_func()->channels; never executed: return d_func()->channels; | 0 | ||||||||||||||||||
| 1341 | } | - | ||||||||||||||||||
| 1342 | - | |||||||||||||||||||
| 1343 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 1344 | void QHttpNetworkConnection::setCacheProxy(const QNetworkProxy &networkProxy) | - | ||||||||||||||||||
| 1345 | { | - | ||||||||||||||||||
| 1346 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1347 | d->networkProxy = networkProxy; | - | ||||||||||||||||||
| 1348 | // update the authenticator | - | ||||||||||||||||||
| 1349 | if (!d->networkProxy.user().isEmpty()) {
| 0-551 | ||||||||||||||||||
| 1350 | for (int i = 0; i < d->channelCount; ++i) {
| 0 | ||||||||||||||||||
| 1351 | d->channels[i].proxyAuthenticator.setUser(d->networkProxy.user()); | - | ||||||||||||||||||
| 1352 | d->channels[i].proxyAuthenticator.setPassword(d->networkProxy.password()); | - | ||||||||||||||||||
| 1353 | } never executed: end of block | 0 | ||||||||||||||||||
| 1354 | } never executed: end of block | 0 | ||||||||||||||||||
| 1355 | } executed 551 times by 8 tests: end of blockExecuted by:
| 551 | ||||||||||||||||||
| 1356 | - | |||||||||||||||||||
| 1357 | QNetworkProxy QHttpNetworkConnection::cacheProxy() const | - | ||||||||||||||||||
| 1358 | { | - | ||||||||||||||||||
| 1359 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||
| 1360 | return d->networkProxy; executed 700 times by 8 tests: return d->networkProxy;Executed by:
| 700 | ||||||||||||||||||
| 1361 | } | - | ||||||||||||||||||
| 1362 | - | |||||||||||||||||||
| 1363 | void QHttpNetworkConnection::setTransparentProxy(const QNetworkProxy &networkProxy) | - | ||||||||||||||||||
| 1364 | { | - | ||||||||||||||||||
| 1365 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1366 | for (int i = 0; i < d->channelCount; ++i)
| 551-3251 | ||||||||||||||||||
| 1367 | d->channels[i].setProxy(networkProxy); executed 3251 times by 8 tests: d->channels[i].setProxy(networkProxy);Executed by:
| 3251 | ||||||||||||||||||
| 1368 | } executed 551 times by 8 tests: end of blockExecuted by:
| 551 | ||||||||||||||||||
| 1369 | - | |||||||||||||||||||
| 1370 | QNetworkProxy QHttpNetworkConnection::transparentProxy() const | - | ||||||||||||||||||
| 1371 | { | - | ||||||||||||||||||
| 1372 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||
| 1373 | return d->channels[0].proxy; executed 700 times by 8 tests: return d->channels[0].proxy;Executed by:
| 700 | ||||||||||||||||||
| 1374 | } | - | ||||||||||||||||||
| 1375 | #endif | - | ||||||||||||||||||
| 1376 | - | |||||||||||||||||||
| 1377 | QHttpNetworkConnection::ConnectionType QHttpNetworkConnection::connectionType() | - | ||||||||||||||||||
| 1378 | { | - | ||||||||||||||||||
| 1379 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1380 | return d->connectionType; executed 227 times by 4 tests: return d->connectionType;Executed by:
| 227 | ||||||||||||||||||
| 1381 | } | - | ||||||||||||||||||
| 1382 | - | |||||||||||||||||||
| 1383 | void QHttpNetworkConnection::setConnectionType(ConnectionType type) | - | ||||||||||||||||||
| 1384 | { | - | ||||||||||||||||||
| 1385 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1386 | d->connectionType = type; | - | ||||||||||||||||||
| 1387 | } executed 91 times by 3 tests: end of blockExecuted by:
| 91 | ||||||||||||||||||
| 1388 | - | |||||||||||||||||||
| 1389 | // SSL support below | - | ||||||||||||||||||
| 1390 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1391 | void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config) | - | ||||||||||||||||||
| 1392 | { | - | ||||||||||||||||||
| 1393 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1394 | if (!d->encrypt)
| 0-57 | ||||||||||||||||||
| 1395 | return; never executed: return; | 0 | ||||||||||||||||||
| 1396 | - | |||||||||||||||||||
| 1397 | // set the config on all channels | - | ||||||||||||||||||
| 1398 | for (int i = 0; i < d->channelCount; ++i)
| 57-287 | ||||||||||||||||||
| 1399 | d->channels[i].setSslConfiguration(config); executed 287 times by 2 tests: d->channels[i].setSslConfiguration(config);Executed by:
| 287 | ||||||||||||||||||
| 1400 | } executed 57 times by 2 tests: end of blockExecuted by:
| 57 | ||||||||||||||||||
| 1401 | - | |||||||||||||||||||
| 1402 | QSharedPointer<QSslContext> QHttpNetworkConnection::sslContext() | - | ||||||||||||||||||
| 1403 | { | - | ||||||||||||||||||
| 1404 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1405 | return d->sslContext; executed 274 times by 3 tests: return d->sslContext;Executed by:
| 274 | ||||||||||||||||||
| 1406 | } | - | ||||||||||||||||||
| 1407 | - | |||||||||||||||||||
| 1408 | void QHttpNetworkConnection::setSslContext(QSharedPointer<QSslContext> context) | - | ||||||||||||||||||
| 1409 | { | - | ||||||||||||||||||
| 1410 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1411 | d->sslContext = qMove(context); | - | ||||||||||||||||||
| 1412 | } executed 95 times by 3 tests: end of blockExecuted by:
| 95 | ||||||||||||||||||
| 1413 | - | |||||||||||||||||||
| 1414 | void QHttpNetworkConnection::ignoreSslErrors(int channel) | - | ||||||||||||||||||
| 1415 | { | - | ||||||||||||||||||
| 1416 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1417 | if (!d->encrypt)
| 0-34 | ||||||||||||||||||
| 1418 | return; never executed: return; | 0 | ||||||||||||||||||
| 1419 | - | |||||||||||||||||||
| 1420 | if (channel == -1) { // ignore for all channels
| 0-34 | ||||||||||||||||||
| 1421 | for (int i = 0; i < d->channelCount; ++i) {
| 34-174 | ||||||||||||||||||
| 1422 | d->channels[i].ignoreSslErrors(); | - | ||||||||||||||||||
| 1423 | } executed 174 times by 3 tests: end of blockExecuted by:
| 174 | ||||||||||||||||||
| 1424 | - | |||||||||||||||||||
| 1425 | } else { executed 34 times by 3 tests: end of blockExecuted by:
| 34 | ||||||||||||||||||
| 1426 | d->channels[channel].ignoreSslErrors(); | - | ||||||||||||||||||
| 1427 | } never executed: end of block | 0 | ||||||||||||||||||
| 1428 | } | - | ||||||||||||||||||
| 1429 | - | |||||||||||||||||||
| 1430 | void QHttpNetworkConnection::ignoreSslErrors(const QList<QSslError> &errors, int channel) | - | ||||||||||||||||||
| 1431 | { | - | ||||||||||||||||||
| 1432 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
| 1433 | if (!d->encrypt)
| 0-6 | ||||||||||||||||||
| 1434 | return; never executed: return; | 0 | ||||||||||||||||||
| 1435 | - | |||||||||||||||||||
| 1436 | if (channel == -1) { // ignore for all channels
| 0-6 | ||||||||||||||||||
| 1437 | for (int i = 0; i < d->channelCount; ++i) {
| 6-36 | ||||||||||||||||||
| 1438 | d->channels[i].ignoreSslErrors(errors); | - | ||||||||||||||||||
| 1439 | } executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 1440 | - | |||||||||||||||||||
| 1441 | } else { executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 1442 | d->channels[channel].ignoreSslErrors(errors); | - | ||||||||||||||||||
| 1443 | } never executed: end of block | 0 | ||||||||||||||||||
| 1444 | } | - | ||||||||||||||||||
| 1445 | - | |||||||||||||||||||
| 1446 | #endif //QT_NO_SSL | - | ||||||||||||||||||
| 1447 | - | |||||||||||||||||||
| 1448 | void QHttpNetworkConnection::preConnectFinished() | - | ||||||||||||||||||
| 1449 | { | - | ||||||||||||||||||
| 1450 | d_func()->preConnectRequests--; | - | ||||||||||||||||||
| 1451 | } never executed: end of block | 0 | ||||||||||||||||||
| 1452 | - | |||||||||||||||||||
| 1453 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 1454 | // only called from QHttpNetworkConnectionChannel::_q_proxyAuthenticationRequired, not | - | ||||||||||||||||||
| 1455 | // from QHttpNetworkConnectionChannel::handleAuthenticationChallenge | - | ||||||||||||||||||
| 1456 | // e.g. it is for SOCKS proxies which require authentication. | - | ||||||||||||||||||
| 1457 | void QHttpNetworkConnectionPrivate::emitProxyAuthenticationRequired(const QHttpNetworkConnectionChannel *chan, const QNetworkProxy &proxy, QAuthenticator* auth) | - | ||||||||||||||||||
| 1458 | { | - | ||||||||||||||||||
| 1459 | // Also pause the connection because socket notifiers may fire while an user | - | ||||||||||||||||||
| 1460 | // dialog is displaying | - | ||||||||||||||||||
| 1461 | pauseConnection(); | - | ||||||||||||||||||
| 1462 | QHttpNetworkReply *reply; | - | ||||||||||||||||||
| 1463 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1464 | if (connectionType == QHttpNetworkConnection::ConnectionTypeSPDY) {
| 3-39 | ||||||||||||||||||
| 1465 | // we choose the reply to emit the proxyAuth signal from somewhat arbitrarily, | - | ||||||||||||||||||
| 1466 | // but that does not matter because the signal will ultimately be emitted | - | ||||||||||||||||||
| 1467 | // by the QNetworkAccessManager. | - | ||||||||||||||||||
| 1468 | Q_ASSERT(chan->spdyRequestsToSend.count() > 0); | - | ||||||||||||||||||
| 1469 | reply = chan->spdyRequestsToSend.cbegin().value().second; | - | ||||||||||||||||||
| 1470 | } else { // HTTP executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 1471 | #endif // QT_NO_SSL | - | ||||||||||||||||||
| 1472 | reply = chan->reply; | - | ||||||||||||||||||
| 1473 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1474 | } executed 39 times by 1 test: end of blockExecuted by:
| 39 | ||||||||||||||||||
| 1475 | #endif // QT_NO_SSL | - | ||||||||||||||||||
| 1476 | - | |||||||||||||||||||
| 1477 | Q_ASSERT(reply); | - | ||||||||||||||||||
| 1478 | emit reply->proxyAuthenticationRequired(proxy, auth); | - | ||||||||||||||||||
| 1479 | resumeConnection(); | - | ||||||||||||||||||
| 1480 | int i = indexOf(chan->socket); | - | ||||||||||||||||||
| 1481 | copyCredentials(i, auth, true); | - | ||||||||||||||||||
| 1482 | } executed 42 times by 2 tests: end of blockExecuted by:
| 42 | ||||||||||||||||||
| 1483 | #endif | - | ||||||||||||||||||
| 1484 | - | |||||||||||||||||||
| 1485 | - | |||||||||||||||||||
| 1486 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 1487 | - | |||||||||||||||||||
| 1488 | #include "moc_qhttpnetworkconnection_p.cpp" | - | ||||||||||||||||||
| 1489 | - | |||||||||||||||||||
| 1490 | #endif // QT_NO_HTTP | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |