| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qhttpthreaddelegate.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
| 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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
| 29 | ** | - | ||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 31 | ** | - | ||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | //#define QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 35 | #include "qhttpthreaddelegate_p.h" | - | ||||||||||||
| 36 | - | |||||||||||||
| 37 | #include <QThread> | - | ||||||||||||
| 38 | #include <QTimer> | - | ||||||||||||
| 39 | #include <QAuthenticator> | - | ||||||||||||
| 40 | #include <QEventLoop> | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | #include "private/qhttpnetworkreply_p.h" | - | ||||||||||||
| 43 | #include "private/qnetworkaccesscache_p.h" | - | ||||||||||||
| 44 | #include "private/qnoncontiguousbytedevice_p.h" | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | #ifndef QT_NO_HTTP | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | static QNetworkReply::NetworkError statusCodeFromHttp(int httpStatusCode, const QUrl &url) | - | ||||||||||||
| 51 | { | - | ||||||||||||
| 52 | QNetworkReply::NetworkError code; | - | ||||||||||||
| 53 | // we've got an error | - | ||||||||||||
| 54 | switch (httpStatusCode) { | - | ||||||||||||
| 55 | case 400: // Bad Request executed 1 time by 1 test: case 400:Executed by:
| 1 | ||||||||||||
| 56 | code = QNetworkReply::ProtocolInvalidOperationError; | - | ||||||||||||
| 57 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||
| 58 | - | |||||||||||||
| 59 | case 401: // Authorization required never executed: case 401: | 0 | ||||||||||||
| 60 | code = QNetworkReply::AuthenticationRequiredError; | - | ||||||||||||
| 61 | break; never executed: break; | 0 | ||||||||||||
| 62 | - | |||||||||||||
| 63 | case 403: // Access denied executed 1 time by 1 test: case 403:Executed by:
| 1 | ||||||||||||
| 64 | code = QNetworkReply::ContentOperationNotPermittedError; | - | ||||||||||||
| 65 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||
| 66 | - | |||||||||||||
| 67 | case 404: // Not Found executed 5 times by 2 tests: case 404:Executed by:
| 5 | ||||||||||||
| 68 | code = QNetworkReply::ContentNotFoundError; | - | ||||||||||||
| 69 | break; executed 5 times by 2 tests: break;Executed by:
| 5 | ||||||||||||
| 70 | - | |||||||||||||
| 71 | case 405: // Method Not Allowed executed 1 time by 1 test: case 405:Executed by:
| 1 | ||||||||||||
| 72 | code = QNetworkReply::ContentOperationNotPermittedError; | - | ||||||||||||
| 73 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||
| 74 | - | |||||||||||||
| 75 | case 407: never executed: case 407: | 0 | ||||||||||||
| 76 | code = QNetworkReply::ProxyAuthenticationRequiredError; | - | ||||||||||||
| 77 | break; never executed: break; | 0 | ||||||||||||
| 78 | - | |||||||||||||
| 79 | case 409: // Resource Conflict never executed: case 409: | 0 | ||||||||||||
| 80 | code = QNetworkReply::ContentConflictError; | - | ||||||||||||
| 81 | break; never executed: break; | 0 | ||||||||||||
| 82 | - | |||||||||||||
| 83 | case 410: // Content no longer available never executed: case 410: | 0 | ||||||||||||
| 84 | code = QNetworkReply::ContentGoneError; | - | ||||||||||||
| 85 | break; never executed: break; | 0 | ||||||||||||
| 86 | - | |||||||||||||
| 87 | case 418: // I'm a teapot never executed: case 418: | 0 | ||||||||||||
| 88 | code = QNetworkReply::ProtocolInvalidOperationError; | - | ||||||||||||
| 89 | break; never executed: break; | 0 | ||||||||||||
| 90 | - | |||||||||||||
| 91 | case 500: // Internal Server Error never executed: case 500: | 0 | ||||||||||||
| 92 | code = QNetworkReply::InternalServerError; | - | ||||||||||||
| 93 | break; never executed: break; | 0 | ||||||||||||
| 94 | - | |||||||||||||
| 95 | case 501: // Server does not support this functionality executed 1 time by 1 test: case 501:Executed by:
| 1 | ||||||||||||
| 96 | code = QNetworkReply::OperationNotImplementedError; | - | ||||||||||||
| 97 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||
| 98 | - | |||||||||||||
| 99 | case 503: // Service unavailable never executed: case 503: | 0 | ||||||||||||
| 100 | code = QNetworkReply::ServiceUnavailableError; | - | ||||||||||||
| 101 | break; never executed: break; | 0 | ||||||||||||
| 102 | - | |||||||||||||
| 103 | default: never executed: default: | 0 | ||||||||||||
| 104 | if (httpStatusCode > 500) {
| 0 | ||||||||||||
| 105 | // some kind of server error | - | ||||||||||||
| 106 | code = QNetworkReply::UnknownServerError; | - | ||||||||||||
| 107 | } else if (httpStatusCode >= 400) { never executed: end of block
| 0 | ||||||||||||
| 108 | // content error we did not handle above | - | ||||||||||||
| 109 | code = QNetworkReply::UnknownContentError; | - | ||||||||||||
| 110 | } else { never executed: end of block | 0 | ||||||||||||
| 111 | qWarning("QNetworkAccess: got HTTP status code %d which is not expected from url: \"%s\"", | - | ||||||||||||
| 112 | httpStatusCode, qPrintable(url.toString())); | - | ||||||||||||
| 113 | code = QNetworkReply::ProtocolFailure; | - | ||||||||||||
| 114 | } never executed: end of block | 0 | ||||||||||||
| 115 | } | - | ||||||||||||
| 116 | - | |||||||||||||
| 117 | return code; executed 9 times by 2 tests: return code;Executed by:
| 9 | ||||||||||||
| 118 | } | - | ||||||||||||
| 119 | - | |||||||||||||
| 120 | - | |||||||||||||
| 121 | static QByteArray makeCacheKey(QUrl &url, QNetworkProxy *proxy) | - | ||||||||||||
| 122 | { | - | ||||||||||||
| 123 | QString result; | - | ||||||||||||
| 124 | QUrl copy = url; | - | ||||||||||||
| 125 | QString scheme = copy.scheme(); | - | ||||||||||||
| 126 | bool isEncrypted = scheme == QLatin1String("https"); | - | ||||||||||||
| 127 | copy.setPort(copy.port(isEncrypted ? 443 : 80)); | - | ||||||||||||
| 128 | if (scheme == QLatin1String("preconnect-http")) {
| 0-872 | ||||||||||||
| 129 | copy.setScheme(QLatin1String("http")); | - | ||||||||||||
| 130 | } else if (scheme == QLatin1String("preconnect-https")) { never executed: end of block
| 0-872 | ||||||||||||
| 131 | copy.setScheme(QLatin1String("https")); | - | ||||||||||||
| 132 | } never executed: end of block | 0 | ||||||||||||
| 133 | result = copy.toString(QUrl::RemoveUserInfo | QUrl::RemovePath | | - | ||||||||||||
| 134 | QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::FullyEncoded); | - | ||||||||||||
| 135 | - | |||||||||||||
| 136 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||
| 137 | if (proxy && proxy->type() != QNetworkProxy::NoProxy) {
| 0-733 | ||||||||||||
| 138 | QUrl key; | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | switch (proxy->type()) { | - | ||||||||||||
| 141 | case QNetworkProxy::Socks5Proxy: executed 62 times by 2 tests: case QNetworkProxy::Socks5Proxy:Executed by:
| 62 | ||||||||||||
| 142 | key.setScheme(QLatin1String("proxy-socks5")); | - | ||||||||||||
| 143 | break; executed 62 times by 2 tests: break;Executed by:
| 62 | ||||||||||||
| 144 | - | |||||||||||||
| 145 | case QNetworkProxy::HttpProxy: executed 69 times by 2 tests: case QNetworkProxy::HttpProxy:Executed by:
| 69 | ||||||||||||
| 146 | case QNetworkProxy::HttpCachingProxy: executed 8 times by 1 test: case QNetworkProxy::HttpCachingProxy:Executed by:
| 8 | ||||||||||||
| 147 | key.setScheme(QLatin1String("proxy-http")); | - | ||||||||||||
| 148 | break; executed 77 times by 2 tests: break;Executed by:
| 77 | ||||||||||||
| 149 | - | |||||||||||||
| 150 | default: never executed: default: | 0 | ||||||||||||
| 151 | break; never executed: break; | 0 | ||||||||||||
| 152 | } | - | ||||||||||||
| 153 | - | |||||||||||||
| 154 | if (!key.scheme().isEmpty()) {
| 0-139 | ||||||||||||
| 155 | key.setUserName(proxy->user()); | - | ||||||||||||
| 156 | key.setHost(proxy->hostName()); | - | ||||||||||||
| 157 | key.setPort(proxy->port()); | - | ||||||||||||
| 158 | key.setQuery(result); | - | ||||||||||||
| 159 | result = key.toString(QUrl::FullyEncoded); | - | ||||||||||||
| 160 | } executed 139 times by 2 tests: end of blockExecuted by:
| 139 | ||||||||||||
| 161 | } executed 139 times by 2 tests: end of blockExecuted by:
| 139 | ||||||||||||
| 162 | #else | - | ||||||||||||
| 163 | Q_UNUSED(proxy) | - | ||||||||||||
| 164 | #endif | - | ||||||||||||
| 165 | - | |||||||||||||
| 166 | return "http-connection:" + result.toLatin1(); executed 872 times by 8 tests: return "http-connection:" + result.toLatin1();Executed by:
| 872 | ||||||||||||
| 167 | } | - | ||||||||||||
| 168 | - | |||||||||||||
| 169 | class QNetworkAccessCachedHttpConnection: public QHttpNetworkConnection, | - | ||||||||||||
| 170 | public QNetworkAccessCache::CacheableObject | - | ||||||||||||
| 171 | { | - | ||||||||||||
| 172 | // Q_OBJECT | - | ||||||||||||
| 173 | public: | - | ||||||||||||
| 174 | #ifdef QT_NO_BEARERMANAGEMENT | - | ||||||||||||
| 175 | QNetworkAccessCachedHttpConnection(const QString &hostName, quint16 port, bool encrypt, | - | ||||||||||||
| 176 | QHttpNetworkConnection::ConnectionType connectionType) | - | ||||||||||||
| 177 | : QHttpNetworkConnection(hostName, port, encrypt, connectionType) | - | ||||||||||||
| 178 | #else | - | ||||||||||||
| 179 | QNetworkAccessCachedHttpConnection(const QString &hostName, quint16 port, bool encrypt, | - | ||||||||||||
| 180 | QHttpNetworkConnection::ConnectionType connectionType, | - | ||||||||||||
| 181 | QSharedPointer<QNetworkSession> networkSession) | - | ||||||||||||
| 182 | : QHttpNetworkConnection(hostName, port, encrypt, connectionType, /*parent=*/0, | - | ||||||||||||
| 183 | qMove(networkSession)) | - | ||||||||||||
| 184 | #endif | - | ||||||||||||
| 185 | { | - | ||||||||||||
| 186 | setExpires(true); | - | ||||||||||||
| 187 | setShareable(true); | - | ||||||||||||
| 188 | } executed 551 times by 8 tests: end of blockExecuted by:
| 551 | ||||||||||||
| 189 | - | |||||||||||||
| 190 | virtual void dispose() Q_DECL_OVERRIDE | - | ||||||||||||
| 191 | { | - | ||||||||||||
| 192 | #if 0 // sample code; do this right with the API | - | ||||||||||||
| 193 | Q_ASSERT(!isWorking()); | - | ||||||||||||
| 194 | #endif | - | ||||||||||||
| 195 | delete this; | - | ||||||||||||
| 196 | } executed 550 times by 9 tests: end of blockExecuted by:
| 550 | ||||||||||||
| 197 | }; | - | ||||||||||||
| 198 | - | |||||||||||||
| 199 | - | |||||||||||||
| 200 | QThreadStorage<QNetworkAccessCache *> QHttpThreadDelegate::connections; | - | ||||||||||||
| 201 | - | |||||||||||||
| 202 | - | |||||||||||||
| 203 | QHttpThreadDelegate::~QHttpThreadDelegate() | - | ||||||||||||
| 204 | { | - | ||||||||||||
| 205 | // It could be that the main thread has asked us to shut down, so we need to delete the HTTP reply | - | ||||||||||||
| 206 | if (httpReply) {
| 8-861 | ||||||||||||
| 207 | delete httpReply; | - | ||||||||||||
| 208 | } executed 8 times by 3 tests: end of blockExecuted by:
| 8 | ||||||||||||
| 209 | - | |||||||||||||
| 210 | // Get the object cache that stores our QHttpNetworkConnection objects | - | ||||||||||||
| 211 | // and release the entry for this QHttpNetworkConnection | - | ||||||||||||
| 212 | if (connections.hasLocalData() && !cacheKey.isEmpty()) {
| 0-793 | ||||||||||||
| 213 | connections.localData()->releaseEntry(cacheKey); | - | ||||||||||||
| 214 | } executed 793 times by 9 tests: end of blockExecuted by:
| 793 | ||||||||||||
| 215 | } executed 869 times by 9 tests: end of blockExecuted by:
| 869 | ||||||||||||
| 216 | - | |||||||||||||
| 217 | - | |||||||||||||
| 218 | QHttpThreadDelegate::QHttpThreadDelegate(QObject *parent) : | - | ||||||||||||
| 219 | QObject(parent) | - | ||||||||||||
| 220 | , ssl(false) | - | ||||||||||||
| 221 | , downloadBufferMaximumSize(0) | - | ||||||||||||
| 222 | , readBufferMaxSize(0) | - | ||||||||||||
| 223 | , bytesEmitted(0) | - | ||||||||||||
| 224 | , pendingDownloadData(0) | - | ||||||||||||
| 225 | , pendingDownloadProgress(0) | - | ||||||||||||
| 226 | , synchronous(false) | - | ||||||||||||
| 227 | , incomingStatusCode(0) | - | ||||||||||||
| 228 | , isPipeliningUsed(false) | - | ||||||||||||
| 229 | , isSpdyUsed(false) | - | ||||||||||||
| 230 | , incomingContentLength(-1) | - | ||||||||||||
| 231 | , incomingErrorCode(QNetworkReply::NoError) | - | ||||||||||||
| 232 | , downloadBuffer(0) | - | ||||||||||||
| 233 | , httpConnection(0) | - | ||||||||||||
| 234 | , httpReply(0) | - | ||||||||||||
| 235 | , synchronousRequestLoop(0) | - | ||||||||||||
| 236 | { | - | ||||||||||||
| 237 | } executed 869 times by 8 tests: end of blockExecuted by:
| 869 | ||||||||||||
| 238 | - | |||||||||||||
| 239 | // This is invoked as BlockingQueuedConnection from QNetworkAccessHttpBackend in the user thread | - | ||||||||||||
| 240 | void QHttpThreadDelegate::startRequestSynchronously() | - | ||||||||||||
| 241 | { | - | ||||||||||||
| 242 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 243 | qDebug() << "QHttpThreadDelegate::startRequestSynchronously() thread=" << QThread::currentThreadId(); | - | ||||||||||||
| 244 | #endif | - | ||||||||||||
| 245 | synchronous = true; | - | ||||||||||||
| 246 | - | |||||||||||||
| 247 | QEventLoop synchronousRequestLoop; | - | ||||||||||||
| 248 | this->synchronousRequestLoop = &synchronousRequestLoop; | - | ||||||||||||
| 249 | - | |||||||||||||
| 250 | // Worst case timeout | - | ||||||||||||
| 251 | QTimer::singleShot(30*1000, this, SLOT(abortRequest())); | - | ||||||||||||
| 252 | - | |||||||||||||
| 253 | QMetaObject::invokeMethod(this, "startRequest", Qt::QueuedConnection); | - | ||||||||||||
| 254 | synchronousRequestLoop.exec(); | - | ||||||||||||
| 255 | - | |||||||||||||
| 256 | connections.localData()->releaseEntry(cacheKey); | - | ||||||||||||
| 257 | connections.setLocalData(0); | - | ||||||||||||
| 258 | - | |||||||||||||
| 259 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 260 | qDebug() << "QHttpThreadDelegate::startRequestSynchronously() thread=" << QThread::currentThreadId() << "finished"; | - | ||||||||||||
| 261 | #endif | - | ||||||||||||
| 262 | } executed 76 times by 1 test: end of blockExecuted by:
| 76 | ||||||||||||
| 263 | - | |||||||||||||
| 264 | - | |||||||||||||
| 265 | // This is invoked as QueuedConnection from QNetworkAccessHttpBackend in the user thread | - | ||||||||||||
| 266 | void QHttpThreadDelegate::startRequest() | - | ||||||||||||
| 267 | { | - | ||||||||||||
| 268 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 269 | qDebug() << "QHttpThreadDelegate::startRequest() thread=" << QThread::currentThreadId(); | - | ||||||||||||
| 270 | #endif | - | ||||||||||||
| 271 | // Check QThreadStorage for the QNetworkAccessCache | - | ||||||||||||
| 272 | // If not there, create this connection cache | - | ||||||||||||
| 273 | if (!connections.hasLocalData()) {
| 332-540 | ||||||||||||
| 274 | connections.setLocalData(new QNetworkAccessCache()); | - | ||||||||||||
| 275 | } executed 540 times by 8 tests: end of blockExecuted by:
| 540 | ||||||||||||
| 276 | - | |||||||||||||
| 277 | // check if we have an open connection to this host | - | ||||||||||||
| 278 | QUrl urlCopy = httpRequest.url(); | - | ||||||||||||
| 279 | urlCopy.setPort(urlCopy.port(ssl ? 443 : 80)); | - | ||||||||||||
| 280 | - | |||||||||||||
| 281 | QHttpNetworkConnection::ConnectionType connectionType | - | ||||||||||||
| 282 | = QHttpNetworkConnection::ConnectionTypeHTTP; | - | ||||||||||||
| 283 | #ifndef QT_NO_SSL | - | ||||||||||||
| 284 | if (httpRequest.isSPDYAllowed() && ssl) {
| 1-759 | ||||||||||||
| 285 | connectionType = QHttpNetworkConnection::ConnectionTypeSPDY; | - | ||||||||||||
| 286 | urlCopy.setScheme(QStringLiteral("spdy")); // to differentiate SPDY requests from HTTPS requests executed 112 times by 1 test: return qstring_literal_temp;Executed by:
| 112 | ||||||||||||
| 287 | QList<QByteArray> nextProtocols; | - | ||||||||||||
| 288 | nextProtocols << QSslConfiguration::NextProtocolSpdy3_0 | - | ||||||||||||
| 289 | << QSslConfiguration::NextProtocolHttp1_1; | - | ||||||||||||
| 290 | incomingSslConfiguration.setAllowedNextProtocols(nextProtocols); | - | ||||||||||||
| 291 | } executed 112 times by 1 test: end of blockExecuted by:
| 112 | ||||||||||||
| 292 | #endif // QT_NO_SSL | - | ||||||||||||
| 293 | - | |||||||||||||
| 294 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||
| 295 | if (transparentProxy.type() != QNetworkProxy::NoProxy)
| 84-788 | ||||||||||||
| 296 | cacheKey = makeCacheKey(urlCopy, &transparentProxy); executed 84 times by 2 tests: cacheKey = makeCacheKey(urlCopy, &transparentProxy);Executed by:
| 84 | ||||||||||||
| 297 | else if (cacheProxy.type() != QNetworkProxy::NoProxy)
| 55-733 | ||||||||||||
| 298 | cacheKey = makeCacheKey(urlCopy, &cacheProxy); executed 55 times by 1 test: cacheKey = makeCacheKey(urlCopy, &cacheProxy);Executed by:
| 55 | ||||||||||||
| 299 | else | - | ||||||||||||
| 300 | #endif | - | ||||||||||||
| 301 | cacheKey = makeCacheKey(urlCopy, 0); executed 733 times by 8 tests: cacheKey = makeCacheKey(urlCopy, 0);Executed by:
| 733 | ||||||||||||
| 302 | - | |||||||||||||
| 303 | - | |||||||||||||
| 304 | // the http object is actually a QHttpNetworkConnection | - | ||||||||||||
| 305 | httpConnection = static_cast<QNetworkAccessCachedHttpConnection *>(connections.localData()->requestEntryNow(cacheKey)); | - | ||||||||||||
| 306 | if (httpConnection == 0) {
| 321-551 | ||||||||||||
| 307 | // no entry in cache; create an object | - | ||||||||||||
| 308 | // the http object is actually a QHttpNetworkConnection | - | ||||||||||||
| 309 | #ifdef QT_NO_BEARERMANAGEMENT | - | ||||||||||||
| 310 | httpConnection = new QNetworkAccessCachedHttpConnection(urlCopy.host(), urlCopy.port(), ssl, | - | ||||||||||||
| 311 | connectionType); | - | ||||||||||||
| 312 | #else | - | ||||||||||||
| 313 | httpConnection = new QNetworkAccessCachedHttpConnection(urlCopy.host(), urlCopy.port(), ssl, | - | ||||||||||||
| 314 | connectionType, | - | ||||||||||||
| 315 | networkSession); | - | ||||||||||||
| 316 | #endif | - | ||||||||||||
| 317 | #ifndef QT_NO_SSL | - | ||||||||||||
| 318 | // Set the QSslConfiguration from this QNetworkRequest. | - | ||||||||||||
| 319 | if (ssl && incomingSslConfiguration != QSslConfiguration::defaultConfiguration()) {
| 40-454 | ||||||||||||
| 320 | httpConnection->setSslConfiguration(incomingSslConfiguration); | - | ||||||||||||
| 321 | } executed 57 times by 2 tests: end of blockExecuted by:
| 57 | ||||||||||||
| 322 | #endif | - | ||||||||||||
| 323 | - | |||||||||||||
| 324 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||
| 325 | httpConnection->setTransparentProxy(transparentProxy); | - | ||||||||||||
| 326 | httpConnection->setCacheProxy(cacheProxy); | - | ||||||||||||
| 327 | #endif | - | ||||||||||||
| 328 | - | |||||||||||||
| 329 | // cache the QHttpNetworkConnection corresponding to this cache key | - | ||||||||||||
| 330 | connections.localData()->addEntry(cacheKey, httpConnection); | - | ||||||||||||
| 331 | } else { executed 551 times by 8 tests: end of blockExecuted by:
| 551 | ||||||||||||
| 332 | if (httpRequest.withCredentials()) {
| 1-320 | ||||||||||||
| 333 | QNetworkAuthenticationCredential credential = authenticationManager->fetchCachedCredentials(httpRequest.url(), 0); | - | ||||||||||||
| 334 | if (!credential.user.isEmpty() && !credential.password.isEmpty()) {
| 0-320 | ||||||||||||
| 335 | QAuthenticator auth; | - | ||||||||||||
| 336 | auth.setUser(credential.user); | - | ||||||||||||
| 337 | auth.setPassword(credential.password); | - | ||||||||||||
| 338 | httpConnection->d_func()->copyCredentials(-1, &auth, false); | - | ||||||||||||
| 339 | } never executed: end of block | 0 | ||||||||||||
| 340 | } executed 320 times by 4 tests: end of blockExecuted by:
| 320 | ||||||||||||
| 341 | } executed 321 times by 4 tests: end of blockExecuted by:
| 321 | ||||||||||||
| 342 | - | |||||||||||||
| 343 | - | |||||||||||||
| 344 | // Send the request to the connection | - | ||||||||||||
| 345 | httpReply = httpConnection->sendRequest(httpRequest); | - | ||||||||||||
| 346 | httpReply->setParent(this); | - | ||||||||||||
| 347 | - | |||||||||||||
| 348 | // Connect the reply signals that we need to handle and then forward | - | ||||||||||||
| 349 | if (synchronous) {
| 76-796 | ||||||||||||
| 350 | connect(httpReply,SIGNAL(headerChanged()), this, SLOT(synchronousHeaderChangedSlot())); | - | ||||||||||||
| 351 | connect(httpReply,SIGNAL(finished()), this, SLOT(synchronousFinishedSlot())); | - | ||||||||||||
| 352 | connect(httpReply,SIGNAL(finishedWithError(QNetworkReply::NetworkError,QString)), | - | ||||||||||||
| 353 | this, SLOT(synchronousFinishedWithErrorSlot(QNetworkReply::NetworkError,QString))); | - | ||||||||||||
| 354 | - | |||||||||||||
| 355 | connect(httpReply, SIGNAL(authenticationRequired(QHttpNetworkRequest,QAuthenticator*)), | - | ||||||||||||
| 356 | this, SLOT(synchronousAuthenticationRequiredSlot(QHttpNetworkRequest,QAuthenticator*))); | - | ||||||||||||
| 357 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||
| 358 | connect(httpReply, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), | - | ||||||||||||
| 359 | this, SLOT(synchronousProxyAuthenticationRequiredSlot(QNetworkProxy,QAuthenticator*))); | - | ||||||||||||
| 360 | #endif | - | ||||||||||||
| 361 | - | |||||||||||||
| 362 | // Don't care about ignored SSL errors for now in the synchronous HTTP case. | - | ||||||||||||
| 363 | } else if (!synchronous) { executed 76 times by 1 test: end of blockExecuted by:
| 0-796 | ||||||||||||
| 364 | connect(httpReply,SIGNAL(headerChanged()), this, SLOT(headerChangedSlot())); | - | ||||||||||||
| 365 | connect(httpReply,SIGNAL(finished()), this, SLOT(finishedSlot())); | - | ||||||||||||
| 366 | connect(httpReply,SIGNAL(finishedWithError(QNetworkReply::NetworkError,QString)), | - | ||||||||||||
| 367 | this, SLOT(finishedWithErrorSlot(QNetworkReply::NetworkError,QString))); | - | ||||||||||||
| 368 | // some signals are only interesting when normal asynchronous style is used | - | ||||||||||||
| 369 | connect(httpReply,SIGNAL(readyRead()), this, SLOT(readyReadSlot())); | - | ||||||||||||
| 370 | connect(httpReply,SIGNAL(dataReadProgress(qint64,qint64)), this, SLOT(dataReadProgressSlot(qint64,qint64))); | - | ||||||||||||
| 371 | #ifndef QT_NO_SSL | - | ||||||||||||
| 372 | connect(httpReply,SIGNAL(encrypted()), this, SLOT(encryptedSlot())); | - | ||||||||||||
| 373 | connect(httpReply,SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrorsSlot(QList<QSslError>))); | - | ||||||||||||
| 374 | connect(httpReply,SIGNAL(preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)), | - | ||||||||||||
| 375 | this, SLOT(preSharedKeyAuthenticationRequiredSlot(QSslPreSharedKeyAuthenticator*))); | - | ||||||||||||
| 376 | #endif | - | ||||||||||||
| 377 | - | |||||||||||||
| 378 | // In the asynchronous HTTP case we can just forward those signals | - | ||||||||||||
| 379 | // Connect the reply signals that we can directly forward | - | ||||||||||||
| 380 | connect(httpReply, SIGNAL(authenticationRequired(QHttpNetworkRequest,QAuthenticator*)), | - | ||||||||||||
| 381 | this, SIGNAL(authenticationRequired(QHttpNetworkRequest,QAuthenticator*))); | - | ||||||||||||
| 382 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||
| 383 | connect(httpReply, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), | - | ||||||||||||
| 384 | this, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); | - | ||||||||||||
| 385 | #endif | - | ||||||||||||
| 386 | } executed 796 times by 8 tests: end of blockExecuted by:
| 796 | ||||||||||||
| 387 | - | |||||||||||||
| 388 | connect(httpReply, SIGNAL(cacheCredentials(QHttpNetworkRequest,QAuthenticator*)), | - | ||||||||||||
| 389 | this, SLOT(cacheCredentialsSlot(QHttpNetworkRequest,QAuthenticator*))); | - | ||||||||||||
| 390 | } executed 872 times by 8 tests: end of blockExecuted by:
| 872 | ||||||||||||
| 391 | - | |||||||||||||
| 392 | // This gets called from the user thread or by the synchronous HTTP timeout timer | - | ||||||||||||
| 393 | void QHttpThreadDelegate::abortRequest() | - | ||||||||||||
| 394 | { | - | ||||||||||||
| 395 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 396 | qDebug() << "QHttpThreadDelegate::abortRequest() thread=" << QThread::currentThreadId() << "sync=" << synchronous; | - | ||||||||||||
| 397 | #endif | - | ||||||||||||
| 398 | if (httpReply) {
| 18-118 | ||||||||||||
| 399 | httpReply->abort(); | - | ||||||||||||
| 400 | delete httpReply; | - | ||||||||||||
| 401 | httpReply = 0; | - | ||||||||||||
| 402 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||
| 403 | - | |||||||||||||
| 404 | // Got aborted by the timeout timer | - | ||||||||||||
| 405 | if (synchronous) {
| 0-136 | ||||||||||||
| 406 | incomingErrorCode = QNetworkReply::TimeoutError; | - | ||||||||||||
| 407 | QMetaObject::invokeMethod(synchronousRequestLoop, "quit", Qt::QueuedConnection); | - | ||||||||||||
| 408 | } else { never executed: end of block | 0 | ||||||||||||
| 409 | //only delete this for asynchronous mode or QNetworkAccessHttpBackend will crash - see QNetworkAccessHttpBackend::postRequest() | - | ||||||||||||
| 410 | this->deleteLater(); | - | ||||||||||||
| 411 | } executed 136 times by 2 tests: end of blockExecuted by:
| 136 | ||||||||||||
| 412 | } | - | ||||||||||||
| 413 | - | |||||||||||||
| 414 | void QHttpThreadDelegate::readBufferSizeChanged(qint64 size) | - | ||||||||||||
| 415 | { | - | ||||||||||||
| 416 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 417 | qDebug() << "QHttpThreadDelegate::readBufferSizeChanged() size " << size; | - | ||||||||||||
| 418 | #endif | - | ||||||||||||
| 419 | if (httpReply) {
| 0-18 | ||||||||||||
| 420 | httpReply->setDownstreamLimited(size > 0); | - | ||||||||||||
| 421 | httpReply->setReadBufferSize(size); | - | ||||||||||||
| 422 | readBufferMaxSize = size; | - | ||||||||||||
| 423 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||
| 424 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||
| 425 | - | |||||||||||||
| 426 | void QHttpThreadDelegate::readBufferFreed(qint64 size) | - | ||||||||||||
| 427 | { | - | ||||||||||||
| 428 | if (readBufferMaxSize) {
| 0-150 | ||||||||||||
| 429 | bytesEmitted -= size; | - | ||||||||||||
| 430 | - | |||||||||||||
| 431 | QMetaObject::invokeMethod(this, "readyReadSlot", Qt::QueuedConnection); | - | ||||||||||||
| 432 | } executed 150 times by 1 test: end of blockExecuted by:
| 150 | ||||||||||||
| 433 | } executed 150 times by 1 test: end of blockExecuted by:
| 150 | ||||||||||||
| 434 | - | |||||||||||||
| 435 | void QHttpThreadDelegate::readyReadSlot() | - | ||||||||||||
| 436 | { | - | ||||||||||||
| 437 | if (!httpReply)
| 2-11406 | ||||||||||||
| 438 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||
| 439 | - | |||||||||||||
| 440 | // Don't do in zerocopy case | - | ||||||||||||
| 441 | if (!downloadBuffer.isNull())
| 0-11406 | ||||||||||||
| 442 | return; never executed: return; | 0 | ||||||||||||
| 443 | - | |||||||||||||
| 444 | if (readBufferMaxSize) {
| 615-10791 | ||||||||||||
| 445 | if (bytesEmitted < readBufferMaxSize) {
| 17-598 | ||||||||||||
| 446 | qint64 sizeEmitted = 0; | - | ||||||||||||
| 447 | while (httpReply->readAnyAvailable() && (sizeEmitted < (readBufferMaxSize-bytesEmitted))) {
| 45-553 | ||||||||||||
| 448 | if (httpReply->sizeNextBlock() > (readBufferMaxSize-bytesEmitted)) {
| 40-208 | ||||||||||||
| 449 | sizeEmitted = readBufferMaxSize-bytesEmitted; | - | ||||||||||||
| 450 | bytesEmitted += sizeEmitted; | - | ||||||||||||
| 451 | pendingDownloadData->fetchAndAddRelease(1); | - | ||||||||||||
| 452 | emit downloadData(httpReply->read(sizeEmitted)); | - | ||||||||||||
| 453 | } else { executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||
| 454 | sizeEmitted = httpReply->sizeNextBlock(); | - | ||||||||||||
| 455 | bytesEmitted += sizeEmitted; | - | ||||||||||||
| 456 | pendingDownloadData->fetchAndAddRelease(1); | - | ||||||||||||
| 457 | emit downloadData(httpReply->readAny()); | - | ||||||||||||
| 458 | } executed 208 times by 1 test: end of blockExecuted by:
| 208 | ||||||||||||
| 459 | } | - | ||||||||||||
| 460 | } else { executed 598 times by 1 test: end of blockExecuted by:
| 598 | ||||||||||||
| 461 | // We need to wait until we empty data from the read buffer in the reply. | - | ||||||||||||
| 462 | } executed 17 times by 1 test: end of blockExecuted by:
| 17 | ||||||||||||
| 463 | - | |||||||||||||
| 464 | } else { | - | ||||||||||||
| 465 | while (httpReply->readAnyAvailable()) {
| 5608-10791 | ||||||||||||
| 466 | pendingDownloadData->fetchAndAddRelease(1); | - | ||||||||||||
| 467 | emit downloadData(httpReply->readAny()); | - | ||||||||||||
| 468 | } executed 5608 times by 4 tests: end of blockExecuted by:
| 5608 | ||||||||||||
| 469 | } executed 10791 times by 4 tests: end of blockExecuted by:
| 10791 | ||||||||||||
| 470 | } | - | ||||||||||||
| 471 | - | |||||||||||||
| 472 | void QHttpThreadDelegate::finishedSlot() | - | ||||||||||||
| 473 | { | - | ||||||||||||
| 474 | if (!httpReply)
| 0-679 | ||||||||||||
| 475 | return; never executed: return; | 0 | ||||||||||||
| 476 | - | |||||||||||||
| 477 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 478 | qDebug() << "QHttpThreadDelegate::finishedSlot() thread=" << QThread::currentThreadId() << "result=" << httpReply->statusCode(); | - | ||||||||||||
| 479 | #endif | - | ||||||||||||
| 480 | - | |||||||||||||
| 481 | // If there is still some data left emit that now | - | ||||||||||||
| 482 | while (httpReply->readAnyAvailable()) {
| 0-679 | ||||||||||||
| 483 | pendingDownloadData->fetchAndAddRelease(1); | - | ||||||||||||
| 484 | emit downloadData(httpReply->readAny()); | - | ||||||||||||
| 485 | } never executed: end of block | 0 | ||||||||||||
| 486 | - | |||||||||||||
| 487 | #ifndef QT_NO_SSL | - | ||||||||||||
| 488 | if (ssl)
| 181-498 | ||||||||||||
| 489 | emit sslConfigurationChanged(httpReply->sslConfiguration()); executed 181 times by 2 tests: sslConfigurationChanged(httpReply->sslConfiguration());Executed by:
| 181 | ||||||||||||
| 490 | #endif | - | ||||||||||||
| 491 | - | |||||||||||||
| 492 | if (httpReply->statusCode() >= 400) {
| 9-670 | ||||||||||||
| 493 | // it's an error reply | - | ||||||||||||
| 494 | QString msg = QLatin1String(QT_TRANSLATE_NOOP("QNetworkReply", | - | ||||||||||||
| 495 | "Error transferring %1 - server replied: %2")); | - | ||||||||||||
| 496 | msg = msg.arg(httpRequest.url().toString(), httpReply->reasonPhrase()); | - | ||||||||||||
| 497 | emit error(statusCodeFromHttp(httpReply->statusCode(), httpRequest.url()), msg); | - | ||||||||||||
| 498 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||
| 499 | - | |||||||||||||
| 500 | if (httpRequest.isFollowRedirects() && httpReply->isRedirecting())
| 2-671 | ||||||||||||
| 501 | emit redirected(httpReply->redirectUrl(), httpReply->statusCode(), httpReply->request().redirectCount() - 1); executed 6 times by 2 tests: redirected(httpReply->redirectUrl(), httpReply->statusCode(), httpReply->request().redirectCount() - 1);Executed by:
| 6 | ||||||||||||
| 502 | - | |||||||||||||
| 503 | emit downloadFinished(); | - | ||||||||||||
| 504 | - | |||||||||||||
| 505 | QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection); | - | ||||||||||||
| 506 | QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection); | - | ||||||||||||
| 507 | httpReply = 0; | - | ||||||||||||
| 508 | } executed 679 times by 7 tests: end of blockExecuted by:
| 679 | ||||||||||||
| 509 | - | |||||||||||||
| 510 | void QHttpThreadDelegate::synchronousFinishedSlot() | - | ||||||||||||
| 511 | { | - | ||||||||||||
| 512 | if (!httpReply)
| 0-63 | ||||||||||||
| 513 | return; never executed: return; | 0 | ||||||||||||
| 514 | - | |||||||||||||
| 515 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 516 | qDebug() << "QHttpThreadDelegate::synchronousFinishedSlot() thread=" << QThread::currentThreadId() << "result=" << httpReply->statusCode(); | - | ||||||||||||
| 517 | #endif | - | ||||||||||||
| 518 | if (httpReply->statusCode() >= 400) {
| 0-63 | ||||||||||||
| 519 | // it's an error reply | - | ||||||||||||
| 520 | QString msg = QLatin1String(QT_TRANSLATE_NOOP("QNetworkReply", | - | ||||||||||||
| 521 | "Error transferring %1 - server replied: %2")); | - | ||||||||||||
| 522 | incomingErrorDetail = msg.arg(httpRequest.url().toString(), httpReply->reasonPhrase()); | - | ||||||||||||
| 523 | incomingErrorCode = statusCodeFromHttp(httpReply->statusCode(), httpRequest.url()); | - | ||||||||||||
| 524 | } never executed: end of block | 0 | ||||||||||||
| 525 | - | |||||||||||||
| 526 | synchronousDownloadData = httpReply->readAll(); | - | ||||||||||||
| 527 | - | |||||||||||||
| 528 | QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection); | - | ||||||||||||
| 529 | QMetaObject::invokeMethod(synchronousRequestLoop, "quit", Qt::QueuedConnection); | - | ||||||||||||
| 530 | httpReply = 0; | - | ||||||||||||
| 531 | } executed 63 times by 1 test: end of blockExecuted by:
| 63 | ||||||||||||
| 532 | - | |||||||||||||
| 533 | void QHttpThreadDelegate::finishedWithErrorSlot(QNetworkReply::NetworkError errorCode, const QString &detail) | - | ||||||||||||
| 534 | { | - | ||||||||||||
| 535 | if (!httpReply)
| 0-91 | ||||||||||||
| 536 | return; never executed: return; | 0 | ||||||||||||
| 537 | - | |||||||||||||
| 538 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 539 | qDebug() << "QHttpThreadDelegate::finishedWithErrorSlot() thread=" << QThread::currentThreadId() << "error=" << errorCode << detail; | - | ||||||||||||
| 540 | #endif | - | ||||||||||||
| 541 | - | |||||||||||||
| 542 | #ifndef QT_NO_SSL | - | ||||||||||||
| 543 | if (ssl)
| 29-62 | ||||||||||||
| 544 | emit sslConfigurationChanged(httpReply->sslConfiguration()); executed 29 times by 2 tests: sslConfigurationChanged(httpReply->sslConfiguration());Executed by:
| 29 | ||||||||||||
| 545 | #endif | - | ||||||||||||
| 546 | emit error(errorCode,detail); | - | ||||||||||||
| 547 | emit downloadFinished(); | - | ||||||||||||
| 548 | - | |||||||||||||
| 549 | - | |||||||||||||
| 550 | QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection); | - | ||||||||||||
| 551 | QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection); | - | ||||||||||||
| 552 | httpReply = 0; | - | ||||||||||||
| 553 | } executed 91 times by 4 tests: end of blockExecuted by:
| 91 | ||||||||||||
| 554 | - | |||||||||||||
| 555 | - | |||||||||||||
| 556 | void QHttpThreadDelegate::synchronousFinishedWithErrorSlot(QNetworkReply::NetworkError errorCode, const QString &detail) | - | ||||||||||||
| 557 | { | - | ||||||||||||
| 558 | if (!httpReply)
| 0-13 | ||||||||||||
| 559 | return; never executed: return; | 0 | ||||||||||||
| 560 | - | |||||||||||||
| 561 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 562 | qDebug() << "QHttpThreadDelegate::synchronousFinishedWithErrorSlot() thread=" << QThread::currentThreadId() << "error=" << errorCode << detail; | - | ||||||||||||
| 563 | #endif | - | ||||||||||||
| 564 | incomingErrorCode = errorCode; | - | ||||||||||||
| 565 | incomingErrorDetail = detail; | - | ||||||||||||
| 566 | - | |||||||||||||
| 567 | synchronousDownloadData = httpReply->readAll(); | - | ||||||||||||
| 568 | - | |||||||||||||
| 569 | QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection); | - | ||||||||||||
| 570 | QMetaObject::invokeMethod(synchronousRequestLoop, "quit", Qt::QueuedConnection); | - | ||||||||||||
| 571 | httpReply = 0; | - | ||||||||||||
| 572 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||
| 573 | - | |||||||||||||
| 574 | static void downloadBufferDeleter(char *ptr) | - | ||||||||||||
| 575 | { | - | ||||||||||||
| 576 | delete[] ptr; | - | ||||||||||||
| 577 | } executed 364 times by 3 tests: end of blockExecuted by:
| 364 | ||||||||||||
| 578 | - | |||||||||||||
| 579 | void QHttpThreadDelegate::headerChangedSlot() | - | ||||||||||||
| 580 | { | - | ||||||||||||
| 581 | if (!httpReply)
| 0-721 | ||||||||||||
| 582 | return; never executed: return; | 0 | ||||||||||||
| 583 | - | |||||||||||||
| 584 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 585 | qDebug() << "QHttpThreadDelegate::headerChangedSlot() thread=" << QThread::currentThreadId(); | - | ||||||||||||
| 586 | #endif | - | ||||||||||||
| 587 | - | |||||||||||||
| 588 | #ifndef QT_NO_SSL | - | ||||||||||||
| 589 | if (ssl)
| 193-528 | ||||||||||||
| 590 | emit sslConfigurationChanged(httpReply->sslConfiguration()); executed 193 times by 2 tests: sslConfigurationChanged(httpReply->sslConfiguration());Executed by:
| 193 | ||||||||||||
| 591 | #endif | - | ||||||||||||
| 592 | - | |||||||||||||
| 593 | // Is using a zerocopy buffer allowed by user and possible with this reply? | - | ||||||||||||
| 594 | if (httpReply->supportsUserProvidedDownloadBuffer()
| 335-386 | ||||||||||||
| 595 | && (downloadBufferMaximumSize > 0) && (httpReply->contentLength() <= downloadBufferMaximumSize)) {
| 0-386 | ||||||||||||
| 596 | QT_TRY { | - | ||||||||||||
| 597 | char *buf = new char[httpReply->contentLength()]; // throws if allocation fails | - | ||||||||||||
| 598 | if (buf) {
| 0-364 | ||||||||||||
| 599 | downloadBuffer = QSharedPointer<char>(buf, downloadBufferDeleter); | - | ||||||||||||
| 600 | httpReply->setUserProvidedDownloadBuffer(buf); | - | ||||||||||||
| 601 | } executed 364 times by 3 tests: end of blockExecuted by:
| 364 | ||||||||||||
| 602 | } QT_CATCH(const std::bad_alloc &) { executed 364 times by 3 tests: end of blockExecuted by:
dead code: { } | - | ||||||||||||
| 603 | // in out of memory situations, don't use downloadbuffer. dead code: { } | - | ||||||||||||
| 604 | } dead code: { } | - | ||||||||||||
| 605 | } | - | ||||||||||||
| 606 | - | |||||||||||||
| 607 | // We fetch this into our own | - | ||||||||||||
| 608 | incomingHeaders = httpReply->header(); | - | ||||||||||||
| 609 | incomingStatusCode = httpReply->statusCode(); | - | ||||||||||||
| 610 | incomingReasonPhrase = httpReply->reasonPhrase(); | - | ||||||||||||
| 611 | isPipeliningUsed = httpReply->isPipeliningUsed(); | - | ||||||||||||
| 612 | incomingContentLength = httpReply->contentLength(); | - | ||||||||||||
| 613 | isSpdyUsed = httpReply->isSpdyUsed(); | - | ||||||||||||
| 614 | - | |||||||||||||
| 615 | emit downloadMetaData(incomingHeaders, | - | ||||||||||||
| 616 | incomingStatusCode, | - | ||||||||||||
| 617 | incomingReasonPhrase, | - | ||||||||||||
| 618 | isPipeliningUsed, | - | ||||||||||||
| 619 | downloadBuffer, | - | ||||||||||||
| 620 | incomingContentLength, | - | ||||||||||||
| 621 | isSpdyUsed); | - | ||||||||||||
| 622 | } executed 721 times by 7 tests: end of blockExecuted by:
| 721 | ||||||||||||
| 623 | - | |||||||||||||
| 624 | void QHttpThreadDelegate::synchronousHeaderChangedSlot() | - | ||||||||||||
| 625 | { | - | ||||||||||||
| 626 | if (!httpReply)
| 0-74 | ||||||||||||
| 627 | return; never executed: return; | 0 | ||||||||||||
| 628 | - | |||||||||||||
| 629 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 630 | qDebug() << "QHttpThreadDelegate::synchronousHeaderChangedSlot() thread=" << QThread::currentThreadId(); | - | ||||||||||||
| 631 | #endif | - | ||||||||||||
| 632 | // Store the information we need in this object, the QNetworkAccessHttpBackend will later read it | - | ||||||||||||
| 633 | incomingHeaders = httpReply->header(); | - | ||||||||||||
| 634 | incomingStatusCode = httpReply->statusCode(); | - | ||||||||||||
| 635 | incomingReasonPhrase = httpReply->reasonPhrase(); | - | ||||||||||||
| 636 | isPipeliningUsed = httpReply->isPipeliningUsed(); | - | ||||||||||||
| 637 | isSpdyUsed = httpReply->isSpdyUsed(); | - | ||||||||||||
| 638 | incomingContentLength = httpReply->contentLength(); | - | ||||||||||||
| 639 | } executed 74 times by 1 test: end of blockExecuted by:
| 74 | ||||||||||||
| 640 | - | |||||||||||||
| 641 | - | |||||||||||||
| 642 | void QHttpThreadDelegate::dataReadProgressSlot(qint64 done, qint64 total) | - | ||||||||||||
| 643 | { | - | ||||||||||||
| 644 | // If we don't have a download buffer don't attempt to go this codepath | - | ||||||||||||
| 645 | // It is not used by QNetworkAccessHttpBackend | - | ||||||||||||
| 646 | if (downloadBuffer.isNull())
| 1495-11236 | ||||||||||||
| 647 | return; executed 11236 times by 4 tests: return;Executed by:
| 11236 | ||||||||||||
| 648 | - | |||||||||||||
| 649 | pendingDownloadProgress->fetchAndAddRelease(1); | - | ||||||||||||
| 650 | emit downloadProgress(done, total); | - | ||||||||||||
| 651 | } executed 1495 times by 3 tests: end of blockExecuted by:
| 1495 | ||||||||||||
| 652 | - | |||||||||||||
| 653 | void QHttpThreadDelegate::cacheCredentialsSlot(const QHttpNetworkRequest &request, QAuthenticator *authenticator) | - | ||||||||||||
| 654 | { | - | ||||||||||||
| 655 | authenticationManager->cacheCredentials(request.url(), authenticator); | - | ||||||||||||
| 656 | } executed 170 times by 1 test: end of blockExecuted by:
| 170 | ||||||||||||
| 657 | - | |||||||||||||
| 658 | - | |||||||||||||
| 659 | #ifndef QT_NO_SSL | - | ||||||||||||
| 660 | void QHttpThreadDelegate::encryptedSlot() | - | ||||||||||||
| 661 | { | - | ||||||||||||
| 662 | if (!httpReply)
| 0-73 | ||||||||||||
| 663 | return; never executed: return; | 0 | ||||||||||||
| 664 | - | |||||||||||||
| 665 | emit sslConfigurationChanged(httpReply->sslConfiguration()); | - | ||||||||||||
| 666 | emit encrypted(); | - | ||||||||||||
| 667 | } executed 73 times by 2 tests: end of blockExecuted by:
| 73 | ||||||||||||
| 668 | - | |||||||||||||
| 669 | void QHttpThreadDelegate::sslErrorsSlot(const QList<QSslError> &errors) | - | ||||||||||||
| 670 | { | - | ||||||||||||
| 671 | if (!httpReply)
| 0-46 | ||||||||||||
| 672 | return; never executed: return; | 0 | ||||||||||||
| 673 | - | |||||||||||||
| 674 | emit sslConfigurationChanged(httpReply->sslConfiguration()); | - | ||||||||||||
| 675 | - | |||||||||||||
| 676 | bool ignoreAll = false; | - | ||||||||||||
| 677 | QList<QSslError> specificErrors; | - | ||||||||||||
| 678 | emit sslErrors(errors, &ignoreAll, &specificErrors); | - | ||||||||||||
| 679 | if (ignoreAll)
| 14-32 | ||||||||||||
| 680 | httpReply->ignoreSslErrors(); executed 32 times by 2 tests: httpReply->ignoreSslErrors();Executed by:
| 32 | ||||||||||||
| 681 | if (!specificErrors.isEmpty())
| 6-40 | ||||||||||||
| 682 | httpReply->ignoreSslErrors(specificErrors); executed 6 times by 1 test: httpReply->ignoreSslErrors(specificErrors);Executed by:
| 6 | ||||||||||||
| 683 | } executed 46 times by 2 tests: end of blockExecuted by:
| 46 | ||||||||||||
| 684 | - | |||||||||||||
| 685 | void QHttpThreadDelegate::preSharedKeyAuthenticationRequiredSlot(QSslPreSharedKeyAuthenticator *authenticator) | - | ||||||||||||
| 686 | { | - | ||||||||||||
| 687 | if (!httpReply)
| 0 | ||||||||||||
| 688 | return; never executed: return; | 0 | ||||||||||||
| 689 | - | |||||||||||||
| 690 | emit preSharedKeyAuthenticationRequired(authenticator); | - | ||||||||||||
| 691 | } never executed: end of block | 0 | ||||||||||||
| 692 | #endif | - | ||||||||||||
| 693 | - | |||||||||||||
| 694 | void QHttpThreadDelegate::synchronousAuthenticationRequiredSlot(const QHttpNetworkRequest &request, QAuthenticator *a) | - | ||||||||||||
| 695 | { | - | ||||||||||||
| 696 | if (!httpReply)
| 0-17 | ||||||||||||
| 697 | return; never executed: return; | 0 | ||||||||||||
| 698 | - | |||||||||||||
| 699 | Q_UNUSED(request); | - | ||||||||||||
| 700 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 701 | qDebug() << "QHttpThreadDelegate::synchronousAuthenticationRequiredSlot() thread=" << QThread::currentThreadId(); | - | ||||||||||||
| 702 | #endif | - | ||||||||||||
| 703 | - | |||||||||||||
| 704 | // Ask the credential cache | - | ||||||||||||
| 705 | QNetworkAuthenticationCredential credential = authenticationManager->fetchCachedCredentials(httpRequest.url(), a); | - | ||||||||||||
| 706 | if (!credential.isNull()) {
| 6-11 | ||||||||||||
| 707 | a->setUser(credential.user); | - | ||||||||||||
| 708 | a->setPassword(credential.password); | - | ||||||||||||
| 709 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||
| 710 | - | |||||||||||||
| 711 | // Disconnect this connection now since we only want to ask the authentication cache once. | - | ||||||||||||
| 712 | QObject::disconnect(httpReply, SIGNAL(authenticationRequired(QHttpNetworkRequest,QAuthenticator*)), | - | ||||||||||||
| 713 | this, SLOT(synchronousAuthenticationRequiredSlot(QHttpNetworkRequest,QAuthenticator*))); | - | ||||||||||||
| 714 | } executed 17 times by 1 test: end of blockExecuted by:
| 17 | ||||||||||||
| 715 | - | |||||||||||||
| 716 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||
| 717 | void QHttpThreadDelegate::synchronousProxyAuthenticationRequiredSlot(const QNetworkProxy &p, QAuthenticator *a) | - | ||||||||||||
| 718 | { | - | ||||||||||||
| 719 | if (!httpReply)
| 0-1 | ||||||||||||
| 720 | return; never executed: return; | 0 | ||||||||||||
| 721 | - | |||||||||||||
| 722 | #ifdef QHTTPTHREADDELEGATE_DEBUG | - | ||||||||||||
| 723 | qDebug() << "QHttpThreadDelegate::synchronousProxyAuthenticationRequiredSlot() thread=" << QThread::currentThreadId(); | - | ||||||||||||
| 724 | #endif | - | ||||||||||||
| 725 | // Ask the credential cache | - | ||||||||||||
| 726 | QNetworkAuthenticationCredential credential = authenticationManager->fetchCachedProxyCredentials(p, a); | - | ||||||||||||
| 727 | if (!credential.isNull()) {
| 0-1 | ||||||||||||
| 728 | a->setUser(credential.user); | - | ||||||||||||
| 729 | a->setPassword(credential.password); | - | ||||||||||||
| 730 | } never executed: end of block | 0 | ||||||||||||
| 731 | - | |||||||||||||
| 732 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||
| 733 | // Disconnect this connection now since we only want to ask the authentication cache once. | - | ||||||||||||
| 734 | QObject::disconnect(httpReply, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), | - | ||||||||||||
| 735 | this, SLOT(synchronousProxyAuthenticationRequiredSlot(QNetworkProxy,QAuthenticator*))); | - | ||||||||||||
| 736 | #endif | - | ||||||||||||
| 737 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 738 | - | |||||||||||||
| 739 | #endif | - | ||||||||||||
| 740 | - | |||||||||||||
| 741 | #endif // QT_NO_HTTP | - | ||||||||||||
| 742 | - | |||||||||||||
| 743 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |