| 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 | } | - | ||||||||||||||||||||||||
| 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 | } | - | ||||||||||||||||||||||||
| 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++) { | - | ||||||||||||||||||||||||
| 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 | } | - | ||||||||||||||||||||||||
| 138 | - | |||||||||||||||||||||||||
| 139 | delayedConnectionTimer.setSingleShot(true); | - | ||||||||||||||||||||||||
| 140 | QObject::connect(&delayedConnectionTimer, SIGNAL(timeout()), q, SLOT(_q_connectDelayedChannel())); | - | ||||||||||||||||||||||||
| 141 | } | - | ||||||||||||||||||||||||
| 142 | - | |||||||||||||||||||||||||
| 143 | void QHttpNetworkConnectionPrivate::pauseConnection() | - | ||||||||||||||||||||||||
| 144 | { | - | ||||||||||||||||||||||||
| 145 | state = PausedState; | - | ||||||||||||||||||||||||
| 146 | - | |||||||||||||||||||||||||
| 147 | // Disable all socket notifiers | - | ||||||||||||||||||||||||
| 148 | for (int i = 0; i < channelCount; i++) { | - | ||||||||||||||||||||||||
| 149 | if (channels[i].socket) { | - | ||||||||||||||||||||||||
| 150 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 151 | if (encrypt) | - | ||||||||||||||||||||||||
| 152 | QSslSocketPrivate::pauseSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket)); | - | ||||||||||||||||||||||||
| 153 | else | - | ||||||||||||||||||||||||
| 154 | #endif | - | ||||||||||||||||||||||||
| 155 | QAbstractSocketPrivate::pauseSocketNotifiers(channels[i].socket); | - | ||||||||||||||||||||||||
| 156 | } | - | ||||||||||||||||||||||||
| 157 | } | - | ||||||||||||||||||||||||
| 158 | } | - | ||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||
| 160 | void QHttpNetworkConnectionPrivate::resumeConnection() | - | ||||||||||||||||||||||||
| 161 | { | - | ||||||||||||||||||||||||
| 162 | state = RunningState; | - | ||||||||||||||||||||||||
| 163 | // Enable all socket notifiers | - | ||||||||||||||||||||||||
| 164 | for (int i = 0; i < channelCount; i++) { | - | ||||||||||||||||||||||||
| 165 | if (channels[i].socket) { | - | ||||||||||||||||||||||||
| 166 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 167 | if (encrypt) | - | ||||||||||||||||||||||||
| 168 | QSslSocketPrivate::resumeSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket)); | - | ||||||||||||||||||||||||
| 169 | else | - | ||||||||||||||||||||||||
| 170 | #endif | - | ||||||||||||||||||||||||
| 171 | QAbstractSocketPrivate::resumeSocketNotifiers(channels[i].socket); | - | ||||||||||||||||||||||||
| 172 | - | |||||||||||||||||||||||||
| 173 | // Resume pending upload if needed | - | ||||||||||||||||||||||||
| 174 | if (channels[i].state == QHttpNetworkConnectionChannel::WritingState) | - | ||||||||||||||||||||||||
| 175 | QMetaObject::invokeMethod(&channels[i], "_q_uploadDataReadyRead", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 176 | } | - | ||||||||||||||||||||||||
| 177 | } | - | ||||||||||||||||||||||||
| 178 | - | |||||||||||||||||||||||||
| 179 | // queue _q_startNextRequest | - | ||||||||||||||||||||||||
| 180 | QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 181 | } | - | ||||||||||||||||||||||||
| 182 | - | |||||||||||||||||||||||||
| 183 | int QHttpNetworkConnectionPrivate::indexOf(QAbstractSocket *socket) const | - | ||||||||||||||||||||||||
| 184 | { | - | ||||||||||||||||||||||||
| 185 | for (int i = 0; i < channelCount; ++i) | - | ||||||||||||||||||||||||
| 186 | if (channels[i].socket == socket) | - | ||||||||||||||||||||||||
| 187 | return i; | - | ||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||
| 189 | qFatal("Called with unknown socket object."); | - | ||||||||||||||||||||||||
| 190 | return 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(); | - | ||||||||||||||||||||||||
| 248 | } | - | ||||||||||||||||||||||||
| 249 | - | |||||||||||||||||||||||||
| 250 | qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const | - | ||||||||||||||||||||||||
| 251 | { | - | ||||||||||||||||||||||||
| 252 | return reply.d_func()->responseData.sizeNextBlock(); | - | ||||||||||||||||||||||||
| 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 | if (const qint64 contentLength = request.contentLength()(); | - | ||||||||||||||||||||||||
| 266 | const qint64 uploadDeviceSize = uploadByteDevice->size(); | - | ||||||||||||||||||||||||
| 267 | if (contentLength
| 1-131 | ||||||||||||||||||||||||
| 268 | // both values known, take the smaller one. | - | ||||||||||||||||||||||||
| 269 | request.setContentLength(qMin(uploadByteDevice->size(), request.uploadDeviceSize, contentLength()));)); | - | ||||||||||||||||||||||||
| 270 | } else if (request.contentLength ()== -1 && uploadByteDevice->size()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(uploadByteDevice->size());uploadDeviceSize); | - | ||||||||||||||||||||||||
| 273 | } else if (request.contentLength ()!= -1 && uploadByteDevice->size()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 (request.Q_UNLIKELY(contentLength ()== -1 && uploadByteDevice->size()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) | - | ||||||||||||||||||||||||
| 369 | i = indexOf(socket); | - | ||||||||||||||||||||||||
| 370 | - | |||||||||||||||||||||||||
| 371 | if (reply) { | - | ||||||||||||||||||||||||
| 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) | - | ||||||||||||||||||||||||
| 382 | channels[i].protocolHandler->setReply(0); | - | ||||||||||||||||||||||||
| 383 | channels[i].request = QHttpNetworkRequest(); | - | ||||||||||||||||||||||||
| 384 | if (socket) | - | ||||||||||||||||||||||||
| 385 | channels[i].requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | // send the next request | - | ||||||||||||||||||||||||
| 388 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 389 | } | - | ||||||||||||||||||||||||
| 390 | } | - | ||||||||||||||||||||||||
| 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) { | - | ||||||||||||||||||||||||
| 398 | if (!isProxy && channels[fromChannel].authMethod == QAuthenticatorPrivate::Ntlm) | - | ||||||||||||||||||||||||
| 399 | return; | - | ||||||||||||||||||||||||
| 400 | if (isProxy && channels[fromChannel].proxyAuthMethod == QAuthenticatorPrivate::Ntlm) | - | ||||||||||||||||||||||||
| 401 | return; | - | ||||||||||||||||||||||||
| 402 | } | - | ||||||||||||||||||||||||
| 403 | - | |||||||||||||||||||||||||
| 404 | // select another channel | - | ||||||||||||||||||||||||
| 405 | QAuthenticator* otherAuth = 0; | - | ||||||||||||||||||||||||
| 406 | for (int i = 0; i < channelCount; ++i) { | - | ||||||||||||||||||||||||
| 407 | if (i == fromChannel) | - | ||||||||||||||||||||||||
| 408 | continue; | - | ||||||||||||||||||||||||
| 409 | if (isProxy) | - | ||||||||||||||||||||||||
| 410 | otherAuth = &channels[i].proxyAuthenticator; | - | ||||||||||||||||||||||||
| 411 | else | - | ||||||||||||||||||||||||
| 412 | otherAuth = &channels[i].authenticator; | - | ||||||||||||||||||||||||
| 413 | // if the credentials are different, copy them | - | ||||||||||||||||||||||||
| 414 | if (otherAuth->user().compare(auth->user())) | - | ||||||||||||||||||||||||
| 415 | otherAuth->setUser(auth->user()); | - | ||||||||||||||||||||||||
| 416 | if (otherAuth->password().compare(auth->password())) | - | ||||||||||||||||||||||||
| 417 | otherAuth->setPassword(auth->password()); | - | ||||||||||||||||||||||||
| 418 | } | - | ||||||||||||||||||||||||
| 419 | } | - | ||||||||||||||||||||||||
| 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) { | - | ||||||||||||||||||||||||
| 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) { | - | ||||||||||||||||||||||||
| 440 | auth = &channels[i].proxyAuthenticator; | - | ||||||||||||||||||||||||
| 441 | channels[i].proxyAuthMethod = authMethod; | - | ||||||||||||||||||||||||
| 442 | } else { | - | ||||||||||||||||||||||||
| 443 | auth = &channels[i].authenticator; | - | ||||||||||||||||||||||||
| 444 | channels[i].authMethod = authMethod; | - | ||||||||||||||||||||||||
| 445 | } | - | ||||||||||||||||||||||||
| 446 | //proceed with the authentication. | - | ||||||||||||||||||||||||
| 447 | if (auth->isNull()) | - | ||||||||||||||||||||||||
| 448 | auth->detach(); | - | ||||||||||||||||||||||||
| 449 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(*auth); | - | ||||||||||||||||||||||||
| 450 | priv->parseHttpResponse(fields, isProxy); | - | ||||||||||||||||||||||||
| 451 | - | |||||||||||||||||||||||||
| 452 | if (priv->phase == QAuthenticatorPrivate::Done) { | - | ||||||||||||||||||||||||
| 453 | pauseConnection(); | - | ||||||||||||||||||||||||
| 454 | if (!isProxy) { | - | ||||||||||||||||||||||||
| 455 | if (channels[i].authenticationCredentialsSent) { | - | ||||||||||||||||||||||||
| 456 | auth->detach(); | - | ||||||||||||||||||||||||
| 457 | priv = QAuthenticatorPrivate::getPrivate(*auth); | - | ||||||||||||||||||||||||
| 458 | priv->hasFailed = true; | - | ||||||||||||||||||||||||
| 459 | priv->phase = QAuthenticatorPrivate::Done; | - | ||||||||||||||||||||||||
| 460 | channels[i].authenticationCredentialsSent = false; | - | ||||||||||||||||||||||||
| 461 | } | - | ||||||||||||||||||||||||
| 462 | emit reply->authenticationRequired(reply->request(), auth); | - | ||||||||||||||||||||||||
| 463 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||||||||
| 464 | } else { | - | ||||||||||||||||||||||||
| 465 | if (channels[i].proxyCredentialsSent) { | - | ||||||||||||||||||||||||
| 466 | auth->detach(); | - | ||||||||||||||||||||||||
| 467 | priv = QAuthenticatorPrivate::getPrivate(*auth); | - | ||||||||||||||||||||||||
| 468 | priv->hasFailed = true; | - | ||||||||||||||||||||||||
| 469 | priv->phase = QAuthenticatorPrivate::Done; | - | ||||||||||||||||||||||||
| 470 | channels[i].proxyCredentialsSent = false; | - | ||||||||||||||||||||||||
| 471 | } | - | ||||||||||||||||||||||||
| 472 | emit reply->proxyAuthenticationRequired(networkProxy, auth); | - | ||||||||||||||||||||||||
| 473 | #endif | - | ||||||||||||||||||||||||
| 474 | } | - | ||||||||||||||||||||||||
| 475 | resumeConnection(); | - | ||||||||||||||||||||||||
| 476 | - | |||||||||||||||||||||||||
| 477 | if (priv->phase != QAuthenticatorPrivate::Done) { | - | ||||||||||||||||||||||||
| 478 | // send any pending requests | - | ||||||||||||||||||||||||
| 479 | copyCredentials(i, auth, isProxy); | - | ||||||||||||||||||||||||
| 480 | } | - | ||||||||||||||||||||||||
| 481 | } else if (priv->phase == QAuthenticatorPrivate::Start) { | - | ||||||||||||||||||||||||
| 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 | } | - | ||||||||||||||||||||||||
| 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()) { | - | ||||||||||||||||||||||||
| 492 | // Reset authenticator so the next request on that channel does not get messed up | - | ||||||||||||||||||||||||
| 493 | auth = 0; | - | ||||||||||||||||||||||||
| 494 | if (isProxy) | - | ||||||||||||||||||||||||
| 495 | channels[i].proxyAuthenticator = QAuthenticator(); | - | ||||||||||||||||||||||||
| 496 | else | - | ||||||||||||||||||||||||
| 497 | channels[i].authenticator = QAuthenticator(); | - | ||||||||||||||||||||||||
| 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 | - | ||||||||||||||||||||||||
| 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; | - | ||||||||||||||||||||||||
| 510 | } | - | ||||||||||||||||||||||||
| 511 | //resend the request | - | ||||||||||||||||||||||||
| 512 | resend = true; | - | ||||||||||||||||||||||||
| 513 | return true; | - | ||||||||||||||||||||||||
| 514 | } | - | ||||||||||||||||||||||||
| 515 | return false; | - | ||||||||||||||||||||||||
| 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 | foreachfor (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) { | - | ||||||||||||||||||||||||
| 573 | if ((channels[i].authMethod != QAuthenticatorPrivate::Ntlm && request.headerField("Authorization").isEmpty()) || channels[i].lastStatus == 401) { | - | ||||||||||||||||||||||||
| 574 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(channels[i].authenticator); | - | ||||||||||||||||||||||||
| 575 | if (priv && priv->method != QAuthenticatorPrivate::None) { | - | ||||||||||||||||||||||||
| 576 | QByteArray response = priv->calculateResponse(request.methodName(), request.uri(false)); | - | ||||||||||||||||||||||||
| 577 | request.setHeaderField("Authorization", response); | - | ||||||||||||||||||||||||
| 578 | channels[i].authenticationCredentialsSent = true; | - | ||||||||||||||||||||||||
| 579 | } | - | ||||||||||||||||||||||||
| 580 | } | - | ||||||||||||||||||||||||
| 581 | } | - | ||||||||||||||||||||||||
| 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) { | - | ||||||||||||||||||||||||
| 585 | if (!(channels[i].proxyAuthMethod == QAuthenticatorPrivate::Ntlm && channels[i].lastStatus != 407)) { | - | ||||||||||||||||||||||||
| 586 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(channels[i].proxyAuthenticator); | - | ||||||||||||||||||||||||
| 587 | if (priv && priv->method != QAuthenticatorPrivate::None) { | - | ||||||||||||||||||||||||
| 588 | QByteArray response = priv->calculateResponse(request.methodName(), request.uri(false)); | - | ||||||||||||||||||||||||
| 589 | request.setHeaderField("Proxy-Authorization", response); | - | ||||||||||||||||||||||||
| 590 | channels[i].proxyCredentialsSent = true; | - | ||||||||||||||||||||||||
| 591 | } | - | ||||||||||||||||||||||||
| 592 | } | - | ||||||||||||||||||||||||
| 593 | } | - | ||||||||||||||||||||||||
| 594 | } | - | ||||||||||||||||||||||||
| 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()) | - | ||||||||||||||||||||||||
| 608 | preConnectRequests++; | - | ||||||||||||||||||||||||
| 609 | - | |||||||||||||||||||||||||
| 610 | if (connectionType == QHttpNetworkConnection::ConnectionTypeHTTP) { | - | ||||||||||||||||||||||||
| 611 | switch (request.priority()) { | - | ||||||||||||||||||||||||
| 612 | case QHttpNetworkRequest::HighPriority: | - | ||||||||||||||||||||||||
| 613 | highPriorityQueue.prepend(pair); | - | ||||||||||||||||||||||||
| 614 | break; | - | ||||||||||||||||||||||||
| 615 | case QHttpNetworkRequest::NormalPriority: | - | ||||||||||||||||||||||||
| 616 | case QHttpNetworkRequest::LowPriority: | - | ||||||||||||||||||||||||
| 617 | lowPriorityQueue.prepend(pair); | - | ||||||||||||||||||||||||
| 618 | break; | - | ||||||||||||||||||||||||
| 619 | } | - | ||||||||||||||||||||||||
| 620 | } | - | ||||||||||||||||||||||||
| 621 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 622 | else { // SPDY | - | ||||||||||||||||||||||||
| 623 | if (!pair.second->d_func()->requestIsPrepared) | - | ||||||||||||||||||||||||
| 624 | prepareRequest(pair); | - | ||||||||||||||||||||||||
| 625 | channels[0].spdyRequestsToSend.insertMulti(request.priority(), pair); | - | ||||||||||||||||||||||||
| 626 | } | - | ||||||||||||||||||||||||
| 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) { | - | ||||||||||||||||||||||||
| 634 | startHostInfoLookup(); | - | ||||||||||||||||||||||||
| 635 | } else if ( networkLayerState == IPv4 || networkLayerState == IPv6 ) { | - | ||||||||||||||||||||||||
| 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 | } | - | ||||||||||||||||||||||||
| 646 | return reply; | - | ||||||||||||||||||||||||
| 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: | - | ||||||||||||||||||||||||
| 656 | highPriorityQueue.prepend(pair); | - | ||||||||||||||||||||||||
| 657 | break; | - | ||||||||||||||||||||||||
| 658 | case QHttpNetworkRequest::NormalPriority: | - | ||||||||||||||||||||||||
| 659 | case QHttpNetworkRequest::LowPriority: | - | ||||||||||||||||||||||||
| 660 | lowPriorityQueue.prepend(pair); | - | ||||||||||||||||||||||||
| 661 | break; | - | ||||||||||||||||||||||||
| 662 | } | - | ||||||||||||||||||||||||
| 663 | - | |||||||||||||||||||||||||
| 664 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 665 | } | - | ||||||||||||||||||||||||
| 666 | - | |||||||||||||||||||||||||
| 667 | bool QHttpNetworkConnectionPrivate::dequeueRequest(QAbstractSocket *socket) | - | ||||||||||||||||||||||||
| 668 | { | - | ||||||||||||||||||||||||
| 669 | int i = 0; | - | ||||||||||||||||||||||||
| 670 | if (socket) | - | ||||||||||||||||||||||||
| 671 | i = indexOf(socket); | - | ||||||||||||||||||||||||
| 672 | - | |||||||||||||||||||||||||
| 673 | if (!highPriorityQueue.isEmpty()) { | - | ||||||||||||||||||||||||
| 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) | - | ||||||||||||||||||||||||
| 677 | prepareRequest(messagePair); | - | ||||||||||||||||||||||||
| 678 | updateChannel(i, messagePair); | - | ||||||||||||||||||||||||
| 679 | return true; | - | ||||||||||||||||||||||||
| 680 | } | - | ||||||||||||||||||||||||
| 681 | - | |||||||||||||||||||||||||
| 682 | if (!lowPriorityQueue.isEmpty()) { | - | ||||||||||||||||||||||||
| 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) | - | ||||||||||||||||||||||||
| 686 | prepareRequest(messagePair); | - | ||||||||||||||||||||||||
| 687 | updateChannel(i, messagePair); | - | ||||||||||||||||||||||||
| 688 | return true; | - | ||||||||||||||||||||||||
| 689 | } | - | ||||||||||||||||||||||||
| 690 | return false; | - | ||||||||||||||||||||||||
| 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 | } | - | ||||||||||||||||||||||||
| 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()) | - | ||||||||||||||||||||||||
| 716 | return; | - | ||||||||||||||||||||||||
| 717 | - | |||||||||||||||||||||||||
| 718 | int i = indexOf(socket); | - | ||||||||||||||||||||||||
| 719 | - | |||||||||||||||||||||||||
| 720 | // return fast if there was no reply right now processed | - | ||||||||||||||||||||||||
| 721 | if (channels[i].reply == 0) | - | ||||||||||||||||||||||||
| 722 | return; | - | ||||||||||||||||||||||||
| 723 | - | |||||||||||||||||||||||||
| 724 | if (! (defaultPipelineLength - channels[i].alreadyPipelinedRequests.length() >= defaultRePipelineLength)) { | - | ||||||||||||||||||||||||
| 725 | return; | - | ||||||||||||||||||||||||
| 726 | } | - | ||||||||||||||||||||||||
| 727 | - | |||||||||||||||||||||||||
| 728 | if (channels[i].pipeliningSupported != QHttpNetworkConnectionChannel::PipeliningProbablySupported) | - | ||||||||||||||||||||||||
| 729 | return; | - | ||||||||||||||||||||||||
| 730 | - | |||||||||||||||||||||||||
| 731 | // the current request that is in must already support pipelining | - | ||||||||||||||||||||||||
| 732 | if (!channels[i].request.isPipeliningAllowed()) | - | ||||||||||||||||||||||||
| 733 | return; | - | ||||||||||||||||||||||||
| 734 | - | |||||||||||||||||||||||||
| 735 | // the current request must be a idempotent (right now we only check GET) | - | ||||||||||||||||||||||||
| 736 | if (channels[i].request.operation() != QHttpNetworkRequest::Get) | - | ||||||||||||||||||||||||
| 737 | return; | - | ||||||||||||||||||||||||
| 738 | - | |||||||||||||||||||||||||
| 739 | // check if socket is connected | - | ||||||||||||||||||||||||
| 740 | if (socket->state() != QAbstractSocket::ConnectedState) | - | ||||||||||||||||||||||||
| 741 | return; | - | ||||||||||||||||||||||||
| 742 | - | |||||||||||||||||||||||||
| 743 | // check for resendCurrent | - | ||||||||||||||||||||||||
| 744 | if (channels[i].resendCurrent) | - | ||||||||||||||||||||||||
| 745 | return; | - | ||||||||||||||||||||||||
| 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() | - | ||||||||||||||||||||||||
| 750 | && (!channels[i].authenticator.user().isEmpty() | - | ||||||||||||||||||||||||
| 751 | || !channels[i].authenticator.password().isEmpty())) | - | ||||||||||||||||||||||||
| 752 | return; | - | ||||||||||||||||||||||||
| 753 | if (!channels[i].proxyAuthenticator.isNull() | - | ||||||||||||||||||||||||
| 754 | && (!channels[i].proxyAuthenticator.user().isEmpty() | - | ||||||||||||||||||||||||
| 755 | || !channels[i].proxyAuthenticator.password().isEmpty())) | - | ||||||||||||||||||||||||
| 756 | return; | - | ||||||||||||||||||||||||
| 757 | - | |||||||||||||||||||||||||
| 758 | // must be in ReadingState or WaitingState | - | ||||||||||||||||||||||||
| 759 | if (! (channels[i].state == QHttpNetworkConnectionChannel::WaitingState | - | ||||||||||||||||||||||||
| 760 | || channels[i].state == QHttpNetworkConnectionChannel::ReadingState)) | - | ||||||||||||||||||||||||
| 761 | return; | - | ||||||||||||||||||||||||
| 762 | - | |||||||||||||||||||||||||
| 763 | int lengthBefore; | - | ||||||||||||||||||||||||
| 764 | while (!highPriorityQueue.isEmpty()) { | - | ||||||||||||||||||||||||
| 765 | lengthBefore = channels[i].alreadyPipelinedRequests.length(); | - | ||||||||||||||||||||||||
| 766 | fillPipeline(highPriorityQueue, channels[i]); | - | ||||||||||||||||||||||||
| 767 | - | |||||||||||||||||||||||||
| 768 | if (channels[i].alreadyPipelinedRequests.length() >= defaultPipelineLength) { | - | ||||||||||||||||||||||||
| 769 | channels[i].pipelineFlush(); | - | ||||||||||||||||||||||||
| 770 | return; | - | ||||||||||||||||||||||||
| 771 | } | - | ||||||||||||||||||||||||
| 772 | - | |||||||||||||||||||||||||
| 773 | if (lengthBefore == channels[i].alreadyPipelinedRequests.length()) | - | ||||||||||||||||||||||||
| 774 | break; // did not process anything, now do the low prio queue | - | ||||||||||||||||||||||||
| 775 | } | - | ||||||||||||||||||||||||
| 776 | - | |||||||||||||||||||||||||
| 777 | while (!lowPriorityQueue.isEmpty()) { | - | ||||||||||||||||||||||||
| 778 | lengthBefore = channels[i].alreadyPipelinedRequests.length(); | - | ||||||||||||||||||||||||
| 779 | fillPipeline(lowPriorityQueue, channels[i]); | - | ||||||||||||||||||||||||
| 780 | - | |||||||||||||||||||||||||
| 781 | if (channels[i].alreadyPipelinedRequests.length() >= defaultPipelineLength) { | - | ||||||||||||||||||||||||
| 782 | channels[i].pipelineFlush(); | - | ||||||||||||||||||||||||
| 783 | return; | - | ||||||||||||||||||||||||
| 784 | } | - | ||||||||||||||||||||||||
| 785 | - | |||||||||||||||||||||||||
| 786 | if (lengthBefore == channels[i].alreadyPipelinedRequests.length()) | - | ||||||||||||||||||||||||
| 787 | break; // did not process anything | - | ||||||||||||||||||||||||
| 788 | } | - | ||||||||||||||||||||||||
| 789 | - | |||||||||||||||||||||||||
| 790 | - | |||||||||||||||||||||||||
| 791 | channels[i].pipelineFlush(); | - | ||||||||||||||||||||||||
| 792 | } | - | ||||||||||||||||||||||||
| 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()) | - | ||||||||||||||||||||||||
| 798 | return true; | - | ||||||||||||||||||||||||
| 799 | - | |||||||||||||||||||||||||
| 800 | for (int i = queue.count() - 1; i >= 0; --i) { | - | ||||||||||||||||||||||||
| 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()) | - | ||||||||||||||||||||||||
| 806 | continue; | - | ||||||||||||||||||||||||
| 807 | - | |||||||||||||||||||||||||
| 808 | // take only GET requests | - | ||||||||||||||||||||||||
| 809 | if (request.operation() != QHttpNetworkRequest::Get) | - | ||||||||||||||||||||||||
| 810 | continue; | - | ||||||||||||||||||||||||
| 811 | - | |||||||||||||||||||||||||
| 812 | if (!request.isPipeliningAllowed()) | - | ||||||||||||||||||||||||
| 813 | continue; | - | ||||||||||||||||||||||||
| 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) | - | ||||||||||||||||||||||||
| 822 | prepareRequest(messagePair); | - | ||||||||||||||||||||||||
| 823 | channel.pipelineInto(messagePair); | - | ||||||||||||||||||||||||
| 824 | - | |||||||||||||||||||||||||
| 825 | // return false because we processed something and need to process again | - | ||||||||||||||||||||||||
| 826 | return false; | - | ||||||||||||||||||||||||
| 827 | } | - | ||||||||||||||||||||||||
| 828 | - | |||||||||||||||||||||||||
| 829 | // return true, the queue has been processed and not changed | - | ||||||||||||||||||||||||
| 830 | return true; | - | ||||||||||||||||||||||||
| 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: | - | ||||||||||||||||||||||||
| 839 | if (socket) | - | ||||||||||||||||||||||||
| 840 | errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(socket->peerName()); | - | ||||||||||||||||||||||||
| 841 | else | - | ||||||||||||||||||||||||
| 842 | errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(hostName); | - | ||||||||||||||||||||||||
| 843 | break; | - | ||||||||||||||||||||||||
| 844 | case QNetworkReply::ConnectionRefusedError: | - | ||||||||||||||||||||||||
| 845 | errorString = QCoreApplication::translate("QHttp", "Connection refused"); | - | ||||||||||||||||||||||||
| 846 | break; | - | ||||||||||||||||||||||||
| 847 | case QNetworkReply::RemoteHostClosedError: | - | ||||||||||||||||||||||||
| 848 | errorString = QCoreApplication::translate("QHttp", "Connection closed"); | - | ||||||||||||||||||||||||
| 849 | break; | - | ||||||||||||||||||||||||
| 850 | case QNetworkReply::TimeoutError: | - | ||||||||||||||||||||||||
| 851 | errorString = QCoreApplication::translate("QAbstractSocket", "Socket operation timed out"); | - | ||||||||||||||||||||||||
| 852 | break; | - | ||||||||||||||||||||||||
| 853 | case QNetworkReply::ProxyAuthenticationRequiredError: | - | ||||||||||||||||||||||||
| 854 | errorString = QCoreApplication::translate("QHttp", "Proxy requires authentication"); | - | ||||||||||||||||||||||||
| 855 | break; | - | ||||||||||||||||||||||||
| 856 | case QNetworkReply::AuthenticationRequiredError: | - | ||||||||||||||||||||||||
| 857 | errorString = QCoreApplication::translate("QHttp", "Host requires authentication"); | - | ||||||||||||||||||||||||
| 858 | break; | - | ||||||||||||||||||||||||
| 859 | case QNetworkReply::ProtocolFailure: | - | ||||||||||||||||||||||||
| 860 | errorString = QCoreApplication::translate("QHttp", "Data corrupted"); | - | ||||||||||||||||||||||||
| 861 | break; | - | ||||||||||||||||||||||||
| 862 | case QNetworkReply::ProtocolUnknownError: | - | ||||||||||||||||||||||||
| 863 | errorString = QCoreApplication::translate("QHttp", "Unknown protocol specified"); | - | ||||||||||||||||||||||||
| 864 | break; | - | ||||||||||||||||||||||||
| 865 | case QNetworkReply::SslHandshakeFailedError: | - | ||||||||||||||||||||||||
| 866 | errorString = QCoreApplication::translate("QHttp", "SSL handshake failed"); | - | ||||||||||||||||||||||||
| 867 | break; | - | ||||||||||||||||||||||||
| 868 | case QNetworkReply::TooManyRedirectsError: | - | ||||||||||||||||||||||||
| 869 | errorString = QCoreApplication::translate("QHttp", "Too many redirects"); | - | ||||||||||||||||||||||||
| 870 | break; | - | ||||||||||||||||||||||||
| 871 | case QNetworkReply::InsecureRedirectError: | - | ||||||||||||||||||||||||
| 872 | errorString = QCoreApplication::translate("QHttp", "Insecure redirect"); | - | ||||||||||||||||||||||||
| 873 | break; | - | ||||||||||||||||||||||||
| 874 | default: | - | ||||||||||||||||||||||||
| 875 | // all other errors are treated as QNetworkReply::UnknownNetworkError | - | ||||||||||||||||||||||||
| 876 | errorString = extraDetail; | - | ||||||||||||||||||||||||
| 877 | break; | - | ||||||||||||||||||||||||
| 878 | } | - | ||||||||||||||||||||||||
| 879 | return errorString; | - | ||||||||||||||||||||||||
| 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) { | - | ||||||||||||||||||||||||
| 890 | // is the reply associated the currently processing of this channel? | - | ||||||||||||||||||||||||
| 891 | if (channels[i].reply == reply) { | - | ||||||||||||||||||||||||
| 892 | channels[i].reply = 0; | - | ||||||||||||||||||||||||
| 893 | if (channels[i].protocolHandler) | - | ||||||||||||||||||||||||
| 894 | channels[i].protocolHandler->setReply(0); | - | ||||||||||||||||||||||||
| 895 | channels[i].request = QHttpNetworkRequest(); | - | ||||||||||||||||||||||||
| 896 | channels[i].resendCurrent = false; | - | ||||||||||||||||||||||||
| 897 | - | |||||||||||||||||||||||||
| 898 | if (!reply->isFinished() && !channels[i].alreadyPipelinedRequests.isEmpty()) { | - | ||||||||||||||||||||||||
| 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 | } | - | ||||||||||||||||||||||||
| 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()) { | - | ||||||||||||||||||||||||
| 908 | if (reply->isAborted()) { | - | ||||||||||||||||||||||||
| 909 | channels[i].abort(); | - | ||||||||||||||||||||||||
| 910 | } else { | - | ||||||||||||||||||||||||
| 911 | channels[i].close(); | - | ||||||||||||||||||||||||
| 912 | } | - | ||||||||||||||||||||||||
| 913 | } | - | ||||||||||||||||||||||||
| 914 | - | |||||||||||||||||||||||||
| 915 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 916 | return; | - | ||||||||||||||||||||||||
| 917 | } | - | ||||||||||||||||||||||||
| 918 | - | |||||||||||||||||||||||||
| 919 | // is the reply inside the pipeline of this channel already? | - | ||||||||||||||||||||||||
| 920 | for (int j = 0; j < channels[i].alreadyPipelinedRequests.length(); j++) { | - | ||||||||||||||||||||||||
| 921 | if (channels[i].alreadyPipelinedRequests.at(j).second == reply) { | - | ||||||||||||||||||||||||
| 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) | - | ||||||||||||||||||||||||
| 932 | channels[i].reply->d_func()->forceConnectionCloseEnabled = true; | - | ||||||||||||||||||||||||
| 933 | - | |||||||||||||||||||||||||
| 934 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 935 | return; | - | ||||||||||||||||||||||||
| 936 | } | - | ||||||||||||||||||||||||
| 937 | } | - | ||||||||||||||||||||||||
| 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) { | - | ||||||||||||||||||||||||
| 943 | if (it.value().second == reply) { | - | ||||||||||||||||||||||||
| 944 | channels[i].spdyRequestsToSend.remove(it.key()); | - | ||||||||||||||||||||||||
| 945 | - | |||||||||||||||||||||||||
| 946 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 947 | return; | - | ||||||||||||||||||||||||
| 948 | } | - | ||||||||||||||||||||||||
| 949 | } | - | ||||||||||||||||||||||||
| 950 | #endif | - | ||||||||||||||||||||||||
| 951 | } | - | ||||||||||||||||||||||||
| 952 | // remove from the high priority queue | - | ||||||||||||||||||||||||
| 953 | if (!highPriorityQueue.isEmpty()) { | - | ||||||||||||||||||||||||
| 954 | for (int j = highPriorityQueue.count() - 1; j >= 0; --j) { | - | ||||||||||||||||||||||||
| 955 | HttpMessagePair messagePair = highPriorityQueue.at(j); | - | ||||||||||||||||||||||||
| 956 | if (messagePair.second == reply) { | - | ||||||||||||||||||||||||
| 957 | highPriorityQueue.removeAt(j); | - | ||||||||||||||||||||||||
| 958 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 959 | return; | - | ||||||||||||||||||||||||
| 960 | } | - | ||||||||||||||||||||||||
| 961 | } | - | ||||||||||||||||||||||||
| 962 | } | - | ||||||||||||||||||||||||
| 963 | // remove from the low priority queue | - | ||||||||||||||||||||||||
| 964 | if (!lowPriorityQueue.isEmpty()) { | - | ||||||||||||||||||||||||
| 965 | for (int j = lowPriorityQueue.count() - 1; j >= 0; --j) { | - | ||||||||||||||||||||||||
| 966 | HttpMessagePair messagePair = lowPriorityQueue.at(j); | - | ||||||||||||||||||||||||
| 967 | if (messagePair.second == reply) { | - | ||||||||||||||||||||||||
| 968 | lowPriorityQueue.removeAt(j); | - | ||||||||||||||||||||||||
| 969 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 970 | return; | - | ||||||||||||||||||||||||
| 971 | } | - | ||||||||||||||||||||||||
| 972 | } | - | ||||||||||||||||||||||||
| 973 | } | - | ||||||||||||||||||||||||
| 974 | } | - | ||||||||||||||||||||||||
| 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) | - | ||||||||||||||||||||||||
| 985 | return; | - | ||||||||||||||||||||||||
| 986 | - | |||||||||||||||||||||||||
| 987 | // If the QHttpNetworkConnection is currently paused then bail out immediately | - | ||||||||||||||||||||||||
| 988 | if (state == PausedState) | - | ||||||||||||||||||||||||
| 989 | return; | - | ||||||||||||||||||||||||
| 990 | - | |||||||||||||||||||||||||
| 991 | //resend the necessary ones. | - | ||||||||||||||||||||||||
| 992 | for (int i = 0; i < channelCount; ++i) { | - | ||||||||||||||||||||||||
| 993 | if (channels[i].resendCurrent && (channels[i].state != QHttpNetworkConnectionChannel::ClosingState)) { | - | ||||||||||||||||||||||||
| 994 | channels[i].resendCurrent = false; | - | ||||||||||||||||||||||||
| 995 | - | |||||||||||||||||||||||||
| 996 | // if this is not possible, error will be emitted and connection terminated | - | ||||||||||||||||||||||||
| 997 | if (!channels[i].resetUploadData()) | - | ||||||||||||||||||||||||
| 998 | continue; | - | ||||||||||||||||||||||||
| 999 | channels[i].sendRequest(); | - | ||||||||||||||||||||||||
| 1000 | } | - | ||||||||||||||||||||||||
| 1001 | } | - | ||||||||||||||||||||||||
| 1002 | - | |||||||||||||||||||||||||
| 1003 | // dequeue new ones | - | ||||||||||||||||||||||||
| 1004 | - | |||||||||||||||||||||||||
| 1005 | switch (connectionType) { | - | ||||||||||||||||||||||||
| 1006 | case QHttpNetworkConnection::ConnectionTypeHTTP: { | - | ||||||||||||||||||||||||
| 1007 | // return fast if there is nothing to do | - | ||||||||||||||||||||||||
| 1008 | if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty()) | - | ||||||||||||||||||||||||
| 1009 | return; | - | ||||||||||||||||||||||||
| 1010 | - | |||||||||||||||||||||||||
| 1011 | // try to get a free AND connected socket | - | ||||||||||||||||||||||||
| 1012 | for (int i = 0; i < channelCount; ++i) { | - | ||||||||||||||||||||||||
| 1013 | if (channels[i].socket) { | - | ||||||||||||||||||||||||
| 1014 | if (!channels[i].reply && !channels[i].isSocketBusy() && channels[i].socket->state() == QAbstractSocket::ConnectedState) { | - | ||||||||||||||||||||||||
| 1015 | if (dequeueRequest(channels[i].socket)) | - | ||||||||||||||||||||||||
| 1016 | channels[i].sendRequest(); | - | ||||||||||||||||||||||||
| 1017 | } | - | ||||||||||||||||||||||||
| 1018 | } | - | ||||||||||||||||||||||||
| 1019 | } | - | ||||||||||||||||||||||||
| 1020 | break; | - | ||||||||||||||||||||||||
| 1021 | } | - | ||||||||||||||||||||||||
| 1022 | case QHttpNetworkConnection::ConnectionTypeSPDY: { | - | ||||||||||||||||||||||||
| 1023 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 1024 | if (channels[0].spdyRequestsToSend.isEmpty()) | - | ||||||||||||||||||||||||
| 1025 | return; | - | ||||||||||||||||||||||||
| 1026 | - | |||||||||||||||||||||||||
| 1027 | if (networkLayerState == IPv4) | - | ||||||||||||||||||||||||
| 1028 | channels[0].networkLayerPreference = QAbstractSocket::IPv4Protocol; | - | ||||||||||||||||||||||||
| 1029 | else if (networkLayerState == IPv6) | - | ||||||||||||||||||||||||
| 1030 | channels[0].networkLayerPreference = QAbstractSocket::IPv6Protocol; | - | ||||||||||||||||||||||||
| 1031 | channels[0].ensureConnection(); | - | ||||||||||||||||||||||||
| 1032 | if (channels[0].socket && channels[0].socket->state() == QAbstractSocket::ConnectedState | - | ||||||||||||||||||||||||
| 1033 | && !channels[0].pendingEncrypt) | - | ||||||||||||||||||||||||
| 1034 | channels[0].sendRequest(); | - | ||||||||||||||||||||||||
| 1035 | #endif // QT_NO_SSL | - | ||||||||||||||||||||||||
| 1036 | break; | - | ||||||||||||||||||||||||
| 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()) | - | ||||||||||||||||||||||||
| 1049 | return; | - | ||||||||||||||||||||||||
| 1050 | for (int i = 0; i < channelCount; i++) | - | ||||||||||||||||||||||||
| 1051 | if (channels[i].socket && channels[i].socket->state() == QAbstractSocket::ConnectedState) | - | ||||||||||||||||||||||||
| 1052 | fillPipeline(channels[i].socket); | - | ||||||||||||||||||||||||
| 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) { | - | ||||||||||||||||||||||||
| 1063 | int normalRequests = queuedRequests - preConnectRequests; | - | ||||||||||||||||||||||||
| 1064 | neededOpenChannels = qMax(normalRequests, preConnectRequests); | - | ||||||||||||||||||||||||
| 1065 | } | - | ||||||||||||||||||||||||
| 1066 | for (int i = 0; i < channelCount && neededOpenChannels > 0; ++i) { | - | ||||||||||||||||||||||||
| 1067 | bool connectChannel = false; | - | ||||||||||||||||||||||||
| 1068 | if (channels[i].socket) { | - | ||||||||||||||||||||||||
| 1069 | if ((channels[i].socket->state() == QAbstractSocket::ConnectingState) | - | ||||||||||||||||||||||||
| 1070 | || (channels[i].socket->state() == QAbstractSocket::HostLookupState) | - | ||||||||||||||||||||||||
| 1071 | || channels[i].pendingEncrypt) // pendingEncrypt == "EncryptingState" | - | ||||||||||||||||||||||||
| 1072 | neededOpenChannels--; | - | ||||||||||||||||||||||||
| 1073 | - | |||||||||||||||||||||||||
| 1074 | if (neededOpenChannels <= 0) | - | ||||||||||||||||||||||||
| 1075 | break; | - | ||||||||||||||||||||||||
| 1076 | if (!channels[i].reply && !channels[i].isSocketBusy() && (channels[i].socket->state() == QAbstractSocket::UnconnectedState)) | - | ||||||||||||||||||||||||
| 1077 | connectChannel = true; | - | ||||||||||||||||||||||||
| 1078 | } else { // not previously used channel | - | ||||||||||||||||||||||||
| 1079 | connectChannel = true; | - | ||||||||||||||||||||||||
| 1080 | } | - | ||||||||||||||||||||||||
| 1081 | - | |||||||||||||||||||||||||
| 1082 | if (connectChannel) { | - | ||||||||||||||||||||||||
| 1083 | if (networkLayerState == IPv4) | - | ||||||||||||||||||||||||
| 1084 | channels[i].networkLayerPreference = QAbstractSocket::IPv4Protocol; | - | ||||||||||||||||||||||||
| 1085 | else if (networkLayerState == IPv6) | - | ||||||||||||||||||||||||
| 1086 | channels[i].networkLayerPreference = QAbstractSocket::IPv6Protocol; | - | ||||||||||||||||||||||||
| 1087 | channels[i].ensureConnection(); | - | ||||||||||||||||||||||||
| 1088 | neededOpenChannels--; | - | ||||||||||||||||||||||||
| 1089 | } | - | ||||||||||||||||||||||||
| 1090 | } | - | ||||||||||||||||||||||||
| 1091 | } | - | ||||||||||||||||||||||||
| 1092 | - | |||||||||||||||||||||||||
| 1093 | - | |||||||||||||||||||||||||
| 1094 | void QHttpNetworkConnectionPrivate::readMoreLater(QHttpNetworkReply *reply) | - | ||||||||||||||||||||||||
| 1095 | { | - | ||||||||||||||||||||||||
| 1096 | for (int i = 0 ; i < channelCount; ++i) { | - | ||||||||||||||||||||||||
| 1097 | if (channels[i].reply == reply) { | - | ||||||||||||||||||||||||
| 1098 | // emulate a readyRead() from the socket | - | ||||||||||||||||||||||||
| 1099 | QMetaObject::invokeMethod(&channels[i], "_q_readyRead", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1100 | return; | - | ||||||||||||||||||||||||
| 1101 | } | - | ||||||||||||||||||||||||
| 1102 | } | - | ||||||||||||||||||||||||
| 1103 | } | - | ||||||||||||||||||||||||
| 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 | if (const QAbstractSocket::NetworkLayerProtocol protocol = temp.protocol()(); | - | ||||||||||||||||||||||||
| 1127 | if (protocol
| 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 (temp.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&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 | foreachconst auto addresses = info.addresses(); | - | ||||||||||||||||||||||||
| 1160 | for (const QHostAddress &address , info.: addresses())) { | - | ||||||||||||||||||||||||
| 1161 | if (const QAbstractSocket::NetworkLayerProtocol protocol = address.protocol()(); | - | ||||||||||||||||||||||||
| 1162 | if (protocol
| 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 (address.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 | QList<for (const HttpMessagePair > spdyPairs =&spdyPair : qAsConst(channels[0].spdyRequestsToSend.values(); | - | ||||||||||||||||||||||||
| for (int a = 0; a < spdyPairs.count(); ++a))) { | ||||||||||||||||||||||||||
| 1193 | // emit error for all replies | - | ||||||||||||||||||||||||
| 1194 | QHttpNetworkReply *currentReply = spdyPairsspdyPair.at(a).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 dequeude-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 | if (const QNetworkConfiguration::BearerType bearerType = networkSession->configuration().bearerType()(); | - | ||||||||||||||||||||||||
| 1229 | if (bearerType
| 0-126 | ||||||||||||||||||||||||
| 1230 | timeout = 800; never executed: timeout = 800; | 0 | ||||||||||||||||||||||||
| 1231 | else if (networkSession->configuration().bearerType ()== QNetworkConfiguration::BearerCDMA2000)
| 0-126 | ||||||||||||||||||||||||
| 1232 | timeout = 500; never executed: timeout = 500; | 0 | ||||||||||||||||||||||||
| 1233 | else if (networkSession->configuration().bearerType ()== QNetworkConfiguration::BearerWCDMA)
| 0-126 | ||||||||||||||||||||||||
| 1234 | timeout = 500; never executed: timeout = 500; | 0 | ||||||||||||||||||||||||
| 1235 | else if (networkSession->configuration().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) { | - | ||||||||||||||||||||||||
| 1254 | if ((channels[i].networkLayerPreference != protocol) && (channels[i].state == QHttpNetworkConnectionChannel::ConnectingState)) { | - | ||||||||||||||||||||||||
| 1255 | channels[i].close(); | - | ||||||||||||||||||||||||
| 1256 | } | - | ||||||||||||||||||||||||
| 1257 | } | - | ||||||||||||||||||||||||
| 1258 | } | - | ||||||||||||||||||||||||
| 1259 | - | |||||||||||||||||||||||||
| 1260 | void QHttpNetworkConnectionPrivate::_q_connectDelayedChannel() | - | ||||||||||||||||||||||||
| 1261 | { | - | ||||||||||||||||||||||||
| 1262 | if (delayIpv4) | - | ||||||||||||||||||||||||
| 1263 | channels[0].ensureConnection(); | - | ||||||||||||||||||||||||
| 1264 | else | - | ||||||||||||||||||||||||
| 1265 | channels[1].ensureConnection(); | - | ||||||||||||||||||||||||
| 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 | } | - | ||||||||||||||||||||||||
| 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 | } | - | ||||||||||||||||||||||||
| 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; | - | ||||||||||||||||||||||||
| 1318 | } | - | ||||||||||||||||||||||||
| 1319 | - | |||||||||||||||||||||||||
| 1320 | quint16 QHttpNetworkConnection::port() const | - | ||||||||||||||||||||||||
| 1321 | { | - | ||||||||||||||||||||||||
| 1322 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1323 | return d->port; | - | ||||||||||||||||||||||||
| 1324 | } | - | ||||||||||||||||||||||||
| 1325 | - | |||||||||||||||||||||||||
| 1326 | QHttpNetworkReply* QHttpNetworkConnection::sendRequest(const QHttpNetworkRequest &request) | - | ||||||||||||||||||||||||
| 1327 | { | - | ||||||||||||||||||||||||
| 1328 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1329 | return d->queueRequest(request); | - | ||||||||||||||||||||||||
| 1330 | } | - | ||||||||||||||||||||||||
| 1331 | - | |||||||||||||||||||||||||
| 1332 | bool QHttpNetworkConnection::isSsl() const | - | ||||||||||||||||||||||||
| 1333 | { | - | ||||||||||||||||||||||||
| 1334 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1335 | return d->encrypt; | - | ||||||||||||||||||||||||
| 1336 | } | - | ||||||||||||||||||||||||
| 1337 | - | |||||||||||||||||||||||||
| 1338 | QHttpNetworkConnectionChannel *QHttpNetworkConnection::channels() const | - | ||||||||||||||||||||||||
| 1339 | { | - | ||||||||||||||||||||||||
| 1340 | return d_func()->channels; | - | ||||||||||||||||||||||||
| 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()) { | - | ||||||||||||||||||||||||
| 1350 | for (int i = 0; i < d->channelCount; ++i) { | - | ||||||||||||||||||||||||
| 1351 | d->channels[i].proxyAuthenticator.setUser(d->networkProxy.user()); | - | ||||||||||||||||||||||||
| 1352 | d->channels[i].proxyAuthenticator.setPassword(d->networkProxy.password()); | - | ||||||||||||||||||||||||
| 1353 | } | - | ||||||||||||||||||||||||
| 1354 | } | - | ||||||||||||||||||||||||
| 1355 | } | - | ||||||||||||||||||||||||
| 1356 | - | |||||||||||||||||||||||||
| 1357 | QNetworkProxy QHttpNetworkConnection::cacheProxy() const | - | ||||||||||||||||||||||||
| 1358 | { | - | ||||||||||||||||||||||||
| 1359 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1360 | return d->networkProxy; | - | ||||||||||||||||||||||||
| 1361 | } | - | ||||||||||||||||||||||||
| 1362 | - | |||||||||||||||||||||||||
| 1363 | void QHttpNetworkConnection::setTransparentProxy(const QNetworkProxy &networkProxy) | - | ||||||||||||||||||||||||
| 1364 | { | - | ||||||||||||||||||||||||
| 1365 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1366 | for (int i = 0; i < d->channelCount; ++i) | - | ||||||||||||||||||||||||
| 1367 | d->channels[i].setProxy(networkProxy); | - | ||||||||||||||||||||||||
| 1368 | } | - | ||||||||||||||||||||||||
| 1369 | - | |||||||||||||||||||||||||
| 1370 | QNetworkProxy QHttpNetworkConnection::transparentProxy() const | - | ||||||||||||||||||||||||
| 1371 | { | - | ||||||||||||||||||||||||
| 1372 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1373 | return d->channels[0].proxy; | - | ||||||||||||||||||||||||
| 1374 | } | - | ||||||||||||||||||||||||
| 1375 | #endif | - | ||||||||||||||||||||||||
| 1376 | - | |||||||||||||||||||||||||
| 1377 | QHttpNetworkConnection::ConnectionType QHttpNetworkConnection::connectionType() | - | ||||||||||||||||||||||||
| 1378 | { | - | ||||||||||||||||||||||||
| 1379 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1380 | return d->connectionType; | - | ||||||||||||||||||||||||
| 1381 | } | - | ||||||||||||||||||||||||
| 1382 | - | |||||||||||||||||||||||||
| 1383 | void QHttpNetworkConnection::setConnectionType(ConnectionType type) | - | ||||||||||||||||||||||||
| 1384 | { | - | ||||||||||||||||||||||||
| 1385 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1386 | d->connectionType = type; | - | ||||||||||||||||||||||||
| 1387 | } | - | ||||||||||||||||||||||||
| 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) | - | ||||||||||||||||||||||||
| 1395 | return; | - | ||||||||||||||||||||||||
| 1396 | - | |||||||||||||||||||||||||
| 1397 | // set the config on all channels | - | ||||||||||||||||||||||||
| 1398 | for (int i = 0; i < d->channelCount; ++i) | - | ||||||||||||||||||||||||
| 1399 | d->channels[i].setSslConfiguration(config); | - | ||||||||||||||||||||||||
| 1400 | } | - | ||||||||||||||||||||||||
| 1401 | - | |||||||||||||||||||||||||
| 1402 | QSharedPointer<QSslContext> QHttpNetworkConnection::sslContext() | - | ||||||||||||||||||||||||
| 1403 | { | - | ||||||||||||||||||||||||
| 1404 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1405 | return d->sslContext; | - | ||||||||||||||||||||||||
| 1406 | } | - | ||||||||||||||||||||||||
| 1407 | - | |||||||||||||||||||||||||
| 1408 | void QHttpNetworkConnection::setSslContext(QSharedPointer<QSslContext> context) | - | ||||||||||||||||||||||||
| 1409 | { | - | ||||||||||||||||||||||||
| 1410 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1411 | d->sslContext = qMove(context); | - | ||||||||||||||||||||||||
| 1412 | } | - | ||||||||||||||||||||||||
| 1413 | - | |||||||||||||||||||||||||
| 1414 | void QHttpNetworkConnection::ignoreSslErrors(int channel) | - | ||||||||||||||||||||||||
| 1415 | { | - | ||||||||||||||||||||||||
| 1416 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1417 | if (!d->encrypt) | - | ||||||||||||||||||||||||
| 1418 | return; | - | ||||||||||||||||||||||||
| 1419 | - | |||||||||||||||||||||||||
| 1420 | if (channel == -1) { // ignore for all channels | - | ||||||||||||||||||||||||
| 1421 | for (int i = 0; i < d->channelCount; ++i) { | - | ||||||||||||||||||||||||
| 1422 | d->channels[i].ignoreSslErrors(); | - | ||||||||||||||||||||||||
| 1423 | } | - | ||||||||||||||||||||||||
| 1424 | - | |||||||||||||||||||||||||
| 1425 | } else { | - | ||||||||||||||||||||||||
| 1426 | d->channels[channel].ignoreSslErrors(); | - | ||||||||||||||||||||||||
| 1427 | } | - | ||||||||||||||||||||||||
| 1428 | } | - | ||||||||||||||||||||||||
| 1429 | - | |||||||||||||||||||||||||
| 1430 | void QHttpNetworkConnection::ignoreSslErrors(const QList<QSslError> &errors, int channel) | - | ||||||||||||||||||||||||
| 1431 | { | - | ||||||||||||||||||||||||
| 1432 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||||||||
| 1433 | if (!d->encrypt) | - | ||||||||||||||||||||||||
| 1434 | return; | - | ||||||||||||||||||||||||
| 1435 | - | |||||||||||||||||||||||||
| 1436 | if (channel == -1) { // ignore for all channels | - | ||||||||||||||||||||||||
| 1437 | for (int i = 0; i < d->channelCount; ++i) { | - | ||||||||||||||||||||||||
| 1438 | d->channels[i].ignoreSslErrors(errors); | - | ||||||||||||||||||||||||
| 1439 | } | - | ||||||||||||||||||||||||
| 1440 | - | |||||||||||||||||||||||||
| 1441 | } else { | - | ||||||||||||||||||||||||
| 1442 | d->channels[channel].ignoreSslErrors(errors); | - | ||||||||||||||||||||||||
| 1443 | } | - | ||||||||||||||||||||||||
| 1444 | } | - | ||||||||||||||||||||||||
| 1445 | - | |||||||||||||||||||||||||
| 1446 | #endif //QT_NO_SSL | - | ||||||||||||||||||||||||
| 1447 | - | |||||||||||||||||||||||||
| 1448 | void QHttpNetworkConnection::preConnectFinished() | - | ||||||||||||||||||||||||
| 1449 | { | - | ||||||||||||||||||||||||
| 1450 | d_func()->preConnectRequests--; | - | ||||||||||||||||||||||||
| 1451 | } | - | ||||||||||||||||||||||||
| 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) { | - | ||||||||||||||||||||||||
| 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 | - | ||||||||||||||||||||||||
| 1471 | #endif // QT_NO_SSL | - | ||||||||||||||||||||||||
| 1472 | reply = chan->reply; | - | ||||||||||||||||||||||||
| 1473 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 1474 | } | - | ||||||||||||||||||||||||
| 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 | } | - | ||||||||||||||||||||||||
| 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 |