| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkreplyhttpimpl.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 | //#define QNETWORKACCESSHTTPBACKEND_DEBUG | - | ||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | #include "qnetworkreplyhttpimpl_p.h" | - | ||||||||||||||||||||||||
| 43 | #include "qnetworkaccessmanager_p.h" | - | ||||||||||||||||||||||||
| 44 | #include "qnetworkaccesscache_p.h" | - | ||||||||||||||||||||||||
| 45 | #include "qabstractnetworkcache.h" | - | ||||||||||||||||||||||||
| 46 | #include "qnetworkrequest.h" | - | ||||||||||||||||||||||||
| 47 | #include "qnetworkreply.h" | - | ||||||||||||||||||||||||
| 48 | #include "qnetworkrequest_p.h" | - | ||||||||||||||||||||||||
| 49 | #include "qnetworkcookie.h" | - | ||||||||||||||||||||||||
| 50 | #include "qnetworkcookie_p.h" | - | ||||||||||||||||||||||||
| 51 | #include "QtCore/qdatetime.h" | - | ||||||||||||||||||||||||
| 52 | #include "QtCore/qelapsedtimer.h" | - | ||||||||||||||||||||||||
| 53 | #include "QtNetwork/qsslconfiguration.h" | - | ||||||||||||||||||||||||
| 54 | #include "qhttpthreaddelegate_p.h" | - | ||||||||||||||||||||||||
| 55 | #include "qthread.h" | - | ||||||||||||||||||||||||
| 56 | #include "QtCore/qcoreapplication.h" | - | ||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||
| 58 | #include <QtCore/private/qthread_p.h> | - | ||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||
| 60 | #include "qnetworkcookiejar.h" | - | ||||||||||||||||||||||||
| 61 | - | |||||||||||||||||||||||||
| 62 | #ifndef QT_NO_HTTP | - | ||||||||||||||||||||||||
| 63 | - | |||||||||||||||||||||||||
| 64 | #include <string.h> // for strchr | - | ||||||||||||||||||||||||
| 65 | - | |||||||||||||||||||||||||
| 66 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 67 | - | |||||||||||||||||||||||||
| 68 | class QNetworkProxy; | - | ||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||
| 70 | static inline bool isSeparator(char c) | - | ||||||||||||||||||||||||
| 71 | { | - | ||||||||||||||||||||||||
| 72 | static const char separators[] = "()<>@,;:\\\"/[]?={}"; | - | ||||||||||||||||||||||||
| 73 | return isLWS(c) || strchr(separators, c) != 0; | - | ||||||||||||||||||||||||
| 74 | } | - | ||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||
| 76 | // ### merge with nextField in cookiejar.cpp | - | ||||||||||||||||||||||||
| 77 | static QHash<QByteArray, QByteArray> parseHttpOptionHeader(const QByteArray &header) | - | ||||||||||||||||||||||||
| 78 | { | - | ||||||||||||||||||||||||
| 79 | // The HTTP header is of the form: | - | ||||||||||||||||||||||||
| 80 | // header = #1(directives) | - | ||||||||||||||||||||||||
| 81 | // directives = token | value-directive | - | ||||||||||||||||||||||||
| 82 | // value-directive = token "=" (token | quoted-string) | - | ||||||||||||||||||||||||
| 83 | QHash<QByteArray, QByteArray> result; | - | ||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||
| 85 | int pos = 0; | - | ||||||||||||||||||||||||
| 86 | while (true) { | - | ||||||||||||||||||||||||
| 87 | // skip spaces | - | ||||||||||||||||||||||||
| 88 | pos = nextNonWhitespace(header, pos); | - | ||||||||||||||||||||||||
| 89 | if (pos == header.length()) | - | ||||||||||||||||||||||||
| 90 | return result; // end of parsing | - | ||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | // pos points to a non-whitespace | - | ||||||||||||||||||||||||
| 93 | int comma = header.indexOf(',', pos); | - | ||||||||||||||||||||||||
| 94 | int equal = header.indexOf('=', pos); | - | ||||||||||||||||||||||||
| 95 | if (comma == pos || equal == pos) | - | ||||||||||||||||||||||||
| 96 | // huh? Broken header. | - | ||||||||||||||||||||||||
| 97 | return result; | - | ||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||
| 99 | // The key name is delimited by either a comma, an equal sign or the end | - | ||||||||||||||||||||||||
| 100 | // of the header, whichever comes first | - | ||||||||||||||||||||||||
| 101 | int end = comma; | - | ||||||||||||||||||||||||
| 102 | if (end == -1) | - | ||||||||||||||||||||||||
| 103 | end = header.length(); | - | ||||||||||||||||||||||||
| 104 | if (equal != -1 && end > equal) | - | ||||||||||||||||||||||||
| 105 | end = equal; // equal sign comes before comma/end | - | ||||||||||||||||||||||||
| 106 | QByteArray key = QByteArray(header.constData() + pos, end - pos).trimmed().toLower(); | - | ||||||||||||||||||||||||
| 107 | pos = end + 1; | - | ||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||
| 109 | if (uint(equal) < uint(comma)) { | - | ||||||||||||||||||||||||
| 110 | // case: token "=" (token | quoted-string) | - | ||||||||||||||||||||||||
| 111 | // skip spaces | - | ||||||||||||||||||||||||
| 112 | pos = nextNonWhitespace(header, pos); | - | ||||||||||||||||||||||||
| 113 | if (pos == header.length()) | - | ||||||||||||||||||||||||
| 114 | // huh? Broken header | - | ||||||||||||||||||||||||
| 115 | return result; | - | ||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||
| 117 | QByteArray value; | - | ||||||||||||||||||||||||
| 118 | value.reserve(header.length() - pos); | - | ||||||||||||||||||||||||
| 119 | if (header.at(pos) == '"') { | - | ||||||||||||||||||||||||
| 120 | // case: quoted-string | - | ||||||||||||||||||||||||
| 121 | // quoted-string = ( <"> *(qdtext | quoted-pair ) <"> ) | - | ||||||||||||||||||||||||
| 122 | // qdtext = <any TEXT except <">> | - | ||||||||||||||||||||||||
| 123 | // quoted-pair = "\" CHAR | - | ||||||||||||||||||||||||
| 124 | ++pos; | - | ||||||||||||||||||||||||
| 125 | while (pos < header.length()) { | - | ||||||||||||||||||||||||
| 126 | char c = header.at(pos); | - | ||||||||||||||||||||||||
| 127 | if (c == '"') { | - | ||||||||||||||||||||||||
| 128 | // end of quoted text | - | ||||||||||||||||||||||||
| 129 | break; | - | ||||||||||||||||||||||||
| 130 | } else if (c == '\\') { | - | ||||||||||||||||||||||||
| 131 | ++pos; | - | ||||||||||||||||||||||||
| 132 | if (pos >= header.length()) | - | ||||||||||||||||||||||||
| 133 | // broken header | - | ||||||||||||||||||||||||
| 134 | return result; | - | ||||||||||||||||||||||||
| 135 | c = header.at(pos); | - | ||||||||||||||||||||||||
| 136 | } | - | ||||||||||||||||||||||||
| 137 | - | |||||||||||||||||||||||||
| 138 | value += c; | - | ||||||||||||||||||||||||
| 139 | ++pos; | - | ||||||||||||||||||||||||
| 140 | } | - | ||||||||||||||||||||||||
| 141 | } else { | - | ||||||||||||||||||||||||
| 142 | // case: token | - | ||||||||||||||||||||||||
| 143 | while (pos < header.length()) { | - | ||||||||||||||||||||||||
| 144 | char c = header.at(pos); | - | ||||||||||||||||||||||||
| 145 | if (isSeparator(c)) | - | ||||||||||||||||||||||||
| 146 | break; | - | ||||||||||||||||||||||||
| 147 | value += c; | - | ||||||||||||||||||||||||
| 148 | ++pos; | - | ||||||||||||||||||||||||
| 149 | } | - | ||||||||||||||||||||||||
| 150 | } | - | ||||||||||||||||||||||||
| 151 | - | |||||||||||||||||||||||||
| 152 | result.insert(key, value); | - | ||||||||||||||||||||||||
| 153 | - | |||||||||||||||||||||||||
| 154 | // find the comma now: | - | ||||||||||||||||||||||||
| 155 | comma = header.indexOf(',', pos); | - | ||||||||||||||||||||||||
| 156 | if (comma == -1) | - | ||||||||||||||||||||||||
| 157 | return result; // end of parsing | - | ||||||||||||||||||||||||
| 158 | pos = comma + 1; | - | ||||||||||||||||||||||||
| 159 | } else { | - | ||||||||||||||||||||||||
| 160 | // case: token | - | ||||||||||||||||||||||||
| 161 | // key is already set | - | ||||||||||||||||||||||||
| 162 | result.insert(key, QByteArray()); | - | ||||||||||||||||||||||||
| 163 | } | - | ||||||||||||||||||||||||
| 164 | } | - | ||||||||||||||||||||||||
| 165 | } | - | ||||||||||||||||||||||||
| 166 | - | |||||||||||||||||||||||||
| 167 | QNetworkReplyHttpImpl::QNetworkReplyHttpImpl(QNetworkAccessManager* const manager, | - | ||||||||||||||||||||||||
| 168 | const QNetworkRequest& request, | - | ||||||||||||||||||||||||
| 169 | QNetworkAccessManager::Operation& operation, | - | ||||||||||||||||||||||||
| 170 | QIODevice* outgoingData) | - | ||||||||||||||||||||||||
| 171 | : QNetworkReply(*new QNetworkReplyHttpImplPrivate, manager) | - | ||||||||||||||||||||||||
| 172 | { | - | ||||||||||||||||||||||||
| 173 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 174 | d->manager = manager; | - | ||||||||||||||||||||||||
| 175 | d->managerPrivate = manager->d_func(); | - | ||||||||||||||||||||||||
| 176 | d->request = request; | - | ||||||||||||||||||||||||
| 177 | d->originalRequest = request; | - | ||||||||||||||||||||||||
| 178 | d->operation = operation; | - | ||||||||||||||||||||||||
| 179 | d->outgoingData = outgoingData; | - | ||||||||||||||||||||||||
| 180 | d->url = request.url(); | - | ||||||||||||||||||||||||
| 181 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 182 | d->sslConfiguration = request.sslConfiguration(); | - | ||||||||||||||||||||||||
| 183 | #endif | - | ||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||
| 185 | // FIXME Later maybe set to Unbuffered, especially if it is zerocopy or from cache? | - | ||||||||||||||||||||||||
| 186 | QIODevice::open(QIODevice::ReadOnly); | - | ||||||||||||||||||||||||
| 187 | - | |||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||
| 189 | // Internal code that does a HTTP reply for the synchronous Ajax | - | ||||||||||||||||||||||||
| 190 | // in Qt WebKit. | - | ||||||||||||||||||||||||
| 191 | QVariant synchronousHttpAttribute = request.attribute( | - | ||||||||||||||||||||||||
| 192 | static_cast<QNetworkRequest::Attribute>(QNetworkRequest::SynchronousRequestAttribute)); | - | ||||||||||||||||||||||||
| 193 | if (synchronousHttpAttribute.isValid()) { | - | ||||||||||||||||||||||||
| 194 | d->synchronous = synchronousHttpAttribute.toBool(); | - | ||||||||||||||||||||||||
| 195 | if (d->synchronous && outgoingData) { | - | ||||||||||||||||||||||||
| 196 | // The synchronous HTTP is a corner case, we will put all upload data in one big QByteArray in the outgoingDataBuffer. | - | ||||||||||||||||||||||||
| 197 | // Yes, this is not the most efficient thing to do, but on the other hand synchronous XHR needs to die anyway. | - | ||||||||||||||||||||||||
| 198 | d->outgoingDataBuffer = QSharedPointer<QRingBuffer>::create(); | - | ||||||||||||||||||||||||
| 199 | qint64 previousDataSize = 0; | - | ||||||||||||||||||||||||
| 200 | do { | - | ||||||||||||||||||||||||
| 201 | previousDataSize = d->outgoingDataBuffer->size(); | - | ||||||||||||||||||||||||
| 202 | d->outgoingDataBuffer->append(d->outgoingData->readAll()); | - | ||||||||||||||||||||||||
| 203 | } while (d->outgoingDataBuffer->size() != previousDataSize); | - | ||||||||||||||||||||||||
| 204 | d->_q_startOperation(); | - | ||||||||||||||||||||||||
| 205 | return; | - | ||||||||||||||||||||||||
| 206 | } | - | ||||||||||||||||||||||||
| 207 | } | - | ||||||||||||||||||||||||
| 208 | - | |||||||||||||||||||||||||
| 209 | - | |||||||||||||||||||||||||
| 210 | if (outgoingData) { | - | ||||||||||||||||||||||||
| 211 | // there is data to be uploaded, e.g. HTTP POST. | - | ||||||||||||||||||||||||
| 212 | - | |||||||||||||||||||||||||
| 213 | if (!d->outgoingData->isSequential()) { | - | ||||||||||||||||||||||||
| 214 | // fixed size non-sequential (random-access) | - | ||||||||||||||||||||||||
| 215 | // just start the operation | - | ||||||||||||||||||||||||
| 216 | QMetaObject::invokeMethod(this, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 217 | // FIXME make direct call? | - | ||||||||||||||||||||||||
| 218 | } else { | - | ||||||||||||||||||||||||
| 219 | bool bufferingDisallowed = | - | ||||||||||||||||||||||||
| 220 | request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute, | - | ||||||||||||||||||||||||
| 221 | false).toBool(); | - | ||||||||||||||||||||||||
| 222 | - | |||||||||||||||||||||||||
| 223 | if (bufferingDisallowed) { | - | ||||||||||||||||||||||||
| 224 | // if a valid content-length header for the request was supplied, we can disable buffering | - | ||||||||||||||||||||||||
| 225 | // if not, we will buffer anyway | - | ||||||||||||||||||||||||
| 226 | if (request.header(QNetworkRequest::ContentLengthHeader).isValid()) { | - | ||||||||||||||||||||||||
| 227 | QMetaObject::invokeMethod(this, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 228 | // FIXME make direct call? | - | ||||||||||||||||||||||||
| 229 | } else { | - | ||||||||||||||||||||||||
| 230 | d->state = d->Buffering; | - | ||||||||||||||||||||||||
| 231 | QMetaObject::invokeMethod(this, "_q_bufferOutgoingData", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 232 | } | - | ||||||||||||||||||||||||
| 233 | } else { | - | ||||||||||||||||||||||||
| 234 | // _q_startOperation will be called when the buffering has finished. | - | ||||||||||||||||||||||||
| 235 | d->state = d->Buffering; | - | ||||||||||||||||||||||||
| 236 | QMetaObject::invokeMethod(this, "_q_bufferOutgoingData", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 237 | } | - | ||||||||||||||||||||||||
| 238 | } | - | ||||||||||||||||||||||||
| 239 | } else { | - | ||||||||||||||||||||||||
| 240 | // No outgoing data (POST, ..) | - | ||||||||||||||||||||||||
| 241 | d->_q_startOperation(); | - | ||||||||||||||||||||||||
| 242 | } | - | ||||||||||||||||||||||||
| 243 | } | - | ||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||
| 245 | QNetworkReplyHttpImpl::~QNetworkReplyHttpImpl() | - | ||||||||||||||||||||||||
| 246 | { | - | ||||||||||||||||||||||||
| 247 | // This will do nothing if the request was already finished or aborted | - | ||||||||||||||||||||||||
| 248 | emit abortHttpRequest(); | - | ||||||||||||||||||||||||
| 249 | } | - | ||||||||||||||||||||||||
| 250 | - | |||||||||||||||||||||||||
| 251 | void QNetworkReplyHttpImpl::close() | - | ||||||||||||||||||||||||
| 252 | { | - | ||||||||||||||||||||||||
| 253 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 254 | - | |||||||||||||||||||||||||
| 255 | if (d->state == QNetworkReplyPrivate::Aborted || | - | ||||||||||||||||||||||||
| 256 | d->state == QNetworkReplyPrivate::Finished) | - | ||||||||||||||||||||||||
| 257 | return; | - | ||||||||||||||||||||||||
| 258 | - | |||||||||||||||||||||||||
| 259 | // According to the documentation close only stops the download | - | ||||||||||||||||||||||||
| 260 | // by closing we can ignore the download part and continue uploading. | - | ||||||||||||||||||||||||
| 261 | QNetworkReply::close(); | - | ||||||||||||||||||||||||
| 262 | - | |||||||||||||||||||||||||
| 263 | // call finished which will emit signals | - | ||||||||||||||||||||||||
| 264 | // FIXME shouldn't this be emitted Queued? | - | ||||||||||||||||||||||||
| 265 | d->error(OperationCanceledError, tr("Operation canceled")); | - | ||||||||||||||||||||||||
| 266 | d->finished(); | - | ||||||||||||||||||||||||
| 267 | } | - | ||||||||||||||||||||||||
| 268 | - | |||||||||||||||||||||||||
| 269 | void QNetworkReplyHttpImpl::abort() | - | ||||||||||||||||||||||||
| 270 | { | - | ||||||||||||||||||||||||
| 271 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 272 | // FIXME | - | ||||||||||||||||||||||||
| 273 | if (d->state == QNetworkReplyPrivate::Finished || d->state == QNetworkReplyPrivate::Aborted) | - | ||||||||||||||||||||||||
| 274 | return; | - | ||||||||||||||||||||||||
| 275 | - | |||||||||||||||||||||||||
| 276 | QNetworkReply::close(); | - | ||||||||||||||||||||||||
| 277 | - | |||||||||||||||||||||||||
| 278 | if (d->state != QNetworkReplyPrivate::Finished) { | - | ||||||||||||||||||||||||
| 279 | // call finished which will emit signals | - | ||||||||||||||||||||||||
| 280 | // FIXME shouldn't this be emitted Queued? | - | ||||||||||||||||||||||||
| 281 | d->error(OperationCanceledError, tr("Operation canceled")); | - | ||||||||||||||||||||||||
| 282 | - | |||||||||||||||||||||||||
| 283 | // If state is WaitingForSession, calling finished has no effect | - | ||||||||||||||||||||||||
| 284 | if (d->state == QNetworkReplyPrivate::WaitingForSession) | - | ||||||||||||||||||||||||
| 285 | d->state = QNetworkReplyPrivate::Working; | - | ||||||||||||||||||||||||
| 286 | d->finished(); | - | ||||||||||||||||||||||||
| 287 | } | - | ||||||||||||||||||||||||
| 288 | - | |||||||||||||||||||||||||
| 289 | d->state = QNetworkReplyPrivate::Aborted; | - | ||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | emit abortHttpRequest(); | - | ||||||||||||||||||||||||
| 292 | } | - | ||||||||||||||||||||||||
| 293 | - | |||||||||||||||||||||||||
| 294 | qint64 QNetworkReplyHttpImpl::bytesAvailable() const | - | ||||||||||||||||||||||||
| 295 | { | - | ||||||||||||||||||||||||
| 296 | Q_D(const QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 297 | - | |||||||||||||||||||||||||
| 298 | // if we load from cache device | - | ||||||||||||||||||||||||
| 299 | if (d->cacheLoadDevice) {
| 0-2143 | ||||||||||||||||||||||||
| 300 | return QNetworkReply::bytesAvailable() + d->cacheLoadDevice->bytesAvailable() + d->downloadMultiBuffer.byteAmount(); never executed: return QNetworkReply::bytesAvailable() + d->cacheLoadDevice->bytesAvailable(); | 0 | ||||||||||||||||||||||||
| 301 | } | - | ||||||||||||||||||||||||
| 302 | - | |||||||||||||||||||||||||
| 303 | // zerocopy buffer | - | ||||||||||||||||||||||||
| 304 | if (d->downloadZerocopyBuffer) {
| 953-1190 | ||||||||||||||||||||||||
| 305 | return QNetworkReply::bytesAvailable() + d->downloadBufferCurrentSize - d->downloadBufferReadPosition; executed 1190 times by 1 test: return QNetworkReply::bytesAvailable() + d->downloadBufferCurrentSize - d->downloadBufferReadPosition;Executed by:
| 1190 | ||||||||||||||||||||||||
| 306 | } | - | ||||||||||||||||||||||||
| 307 | - | |||||||||||||||||||||||||
| 308 | // normal buffer | - | ||||||||||||||||||||||||
| 309 | return QNetworkReply::bytesAvailable() + d->downloadMultiBuffer.byteAmount(); executed 953 times by 1 test: return QNetworkReply::bytesAvailable();Executed by:
| 953 | ||||||||||||||||||||||||
| 310 | } | - | ||||||||||||||||||||||||
| 311 | - | |||||||||||||||||||||||||
| 312 | bool QNetworkReplyHttpImpl::isSequential () const | - | ||||||||||||||||||||||||
| 313 | { | - | ||||||||||||||||||||||||
| 314 | // FIXME In the cache of a cached load or the zero-copy buffer we could actually be non-sequential. | - | ||||||||||||||||||||||||
| 315 | // FIXME however this requires us to implement stuff like seek() too. | - | ||||||||||||||||||||||||
| 316 | return true; | - | ||||||||||||||||||||||||
| 317 | } | - | ||||||||||||||||||||||||
| 318 | - | |||||||||||||||||||||||||
| 319 | qint64 QNetworkReplyHttpImpl::size() const | - | ||||||||||||||||||||||||
| 320 | { | - | ||||||||||||||||||||||||
| 321 | // FIXME At some point, this could return a proper value, e.g. if we're non-sequential. | - | ||||||||||||||||||||||||
| 322 | return QNetworkReply::size(); | - | ||||||||||||||||||||||||
| 323 | } | - | ||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||
| 325 | qint64 QNetworkReplyHttpImpl::readData(char* data, qint64 maxlen) | - | ||||||||||||||||||||||||
| 326 | { | - | ||||||||||||||||||||||||
| 327 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 328 | - | |||||||||||||||||||||||||
| 329 | // cacheload device | - | ||||||||||||||||||||||||
| 330 | if (d->cacheLoadDevice) {
| 0-1342 | ||||||||||||||||||||||||
| 331 | // FIXME bytesdownloaded, position etc? | - | ||||||||||||||||||||||||
| // There is something already in the buffer we buffered before because the user did not read() | ||||||||||||||||||||||||||
| // anything, so we read there first: | ||||||||||||||||||||||||||
| if (!d->downloadMultiBuffer.isEmpty()) { | ||||||||||||||||||||||||||
| return d->downloadMultiBuffer.read(data, maxlen); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 332 | - | |||||||||||||||||||||||||
| 333 | qint64 ret = d->cacheLoadDevice->read(data, maxlen); | - | ||||||||||||||||||||||||
| 334 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
| 335 | } | - | ||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||
| 337 | // zerocopy buffer | - | ||||||||||||||||||||||||
| 338 | if (d->downloadZerocopyBuffer) {
| 576-766 | ||||||||||||||||||||||||
| 339 | // FIXME bytesdownloaded, position etc? | - | ||||||||||||||||||||||||
| 340 | - | |||||||||||||||||||||||||
| 341 | qint64 howMuch = qMin(maxlen, (d->downloadBufferCurrentSize - d->downloadBufferReadPosition)); | - | ||||||||||||||||||||||||
| 342 | memcpy(data, d->downloadZerocopyBuffer + d->downloadBufferReadPosition, howMuch); | - | ||||||||||||||||||||||||
| 343 | d->downloadBufferReadPosition += howMuch; | - | ||||||||||||||||||||||||
| 344 | return howMuch; executed 576 times by 2 tests: return howMuch;Executed by:
| 576 | ||||||||||||||||||||||||
| 345 | - | |||||||||||||||||||||||||
| 346 | } | - | ||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||
| 348 | // normal buffer | - | ||||||||||||||||||||||||
| 349 | if (d->downloadMultiBuffer.isEmpty()) {
| 0-568 | ||||||||||||||||||||||||
| ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
| 350 | executed 568 times by 3 tests: return -1;return -1;Executed by:
executed 568 times by 3 tests: return -1;Executed by:
| 568 | ||||||||||||||||||||||||
| return 0 executed 568 times by 3 tests: ;return -1;Executed by:
executed 568 times by 3 tests: return -1;Executed by:
| ||||||||||||||||||||||||||
| } executed 568 times by 3 tests: return -1;Executed by:
| ||||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||
| 352 | if (maxlen == 1) { | - | ||||||||||||||||||||||||
| // optimization forqint64 getChar() | ||||||||||||||||||||||||||
| *datawasBuffered = d->downloadMultiBuffer.getChar(); | ||||||||||||||||||||||||||
| if (readBufferSize()) | ||||||||||||||||||||||||||
| emit readBufferFreed(1); | ||||||||||||||||||||||||||
| return 1bytesBuffered; | ||||||||||||||||||||||||||
| 353 | } | - | ||||||||||||||||||||||||
| maxlen = qMin<qint64>(maxlen, d->downloadMultiBuffer.byteAmount()); | ||||||||||||||||||||||||||
| qint64 bytesReadbytesBuffered = d->downloadMultiBuffer.read(data, maxlen);0; | ||||||||||||||||||||||||||
| 354 | if (readBufferSize())
| 0-198 | ||||||||||||||||||||||||
| 355 | emit readBufferFreed(bytesReadwasBuffered); executed 198 times by 1 test: readBufferFreed(wasBuffered);Executed by:
| 198 | ||||||||||||||||||||||||
| 356 | return bytesRead0; executed 198 times by 1 test: return 0;Executed by:
| 198 | ||||||||||||||||||||||||
| 357 | } | - | ||||||||||||||||||||||||
| 358 | - | |||||||||||||||||||||||||
| 359 | void QNetworkReplyHttpImpl::setReadBufferSize(qint64 size) | - | ||||||||||||||||||||||||
| 360 | { | - | ||||||||||||||||||||||||
| 361 | QNetworkReply::setReadBufferSize(size); | - | ||||||||||||||||||||||||
| 362 | emit readBufferSizeChanged(size); | - | ||||||||||||||||||||||||
| 363 | return; | - | ||||||||||||||||||||||||
| 364 | } | - | ||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||
| 366 | bool QNetworkReplyHttpImpl::canReadLine () const | - | ||||||||||||||||||||||||
| 367 | { | - | ||||||||||||||||||||||||
| 368 | Q_D(const QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 369 | - | |||||||||||||||||||||||||
| 370 | if (QNetworkReply::canReadLine())
| 1-5 | ||||||||||||||||||||||||
| 371 | return true; executed 1 time by 1 test: return true;Executed by:
| 1 | ||||||||||||||||||||||||
| 372 | - | |||||||||||||||||||||||||
| 373 | if (d->cacheLoadDevice)
| 0-5 | ||||||||||||||||||||||||
| 374 | return d->cacheLoadDevice->canReadLine() || d->downloadMultiBuffer.canReadLine(); never executed: return d->cacheLoadDevice->canReadLine(); | 0 | ||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||
| 376 | if (d->downloadZerocopyBuffer)
| 0-5 | ||||||||||||||||||||||||
| 377 | return memchr(d->downloadZerocopyBuffer + d->downloadBufferReadPosition, '\n', d->downloadBufferCurrentSize - d->downloadBufferReadPosition); executed 5 times by 1 test: return memchr(d->downloadZerocopyBuffer + d->downloadBufferReadPosition, '\n', d->downloadBufferCurrentSize - d->downloadBufferReadPosition);Executed by:
| 5 | ||||||||||||||||||||||||
| 378 | - | |||||||||||||||||||||||||
| 379 | return d->downloadMultiBuffer.canReadLine();false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 380 | } | - | ||||||||||||||||||||||||
| 381 | - | |||||||||||||||||||||||||
| 382 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 383 | void QNetworkReplyHttpImpl::ignoreSslErrors() | - | ||||||||||||||||||||||||
| 384 | { | - | ||||||||||||||||||||||||
| 385 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | d->pendingIgnoreAllSslErrors = true; | - | ||||||||||||||||||||||||
| 388 | } | - | ||||||||||||||||||||||||
| 389 | - | |||||||||||||||||||||||||
| 390 | void QNetworkReplyHttpImpl::ignoreSslErrorsImplementation(const QList<QSslError> &errors) | - | ||||||||||||||||||||||||
| 391 | { | - | ||||||||||||||||||||||||
| 392 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | // the pending list is set if QNetworkReply::ignoreSslErrors(const QList<QSslError> &errors) | - | ||||||||||||||||||||||||
| 395 | // is called before QNetworkAccessManager::get() (or post(), etc.) | - | ||||||||||||||||||||||||
| 396 | d->pendingIgnoreSslErrorsList = errors; | - | ||||||||||||||||||||||||
| 397 | } | - | ||||||||||||||||||||||||
| 398 | - | |||||||||||||||||||||||||
| 399 | void QNetworkReplyHttpImpl::setSslConfigurationImplementation(const QSslConfiguration &newconfig) | - | ||||||||||||||||||||||||
| 400 | { | - | ||||||||||||||||||||||||
| 401 | // Setting a SSL configuration on a reply is not supported. The user needs to set | - | ||||||||||||||||||||||||
| 402 | // her/his QSslConfiguration on the QNetworkRequest. | - | ||||||||||||||||||||||||
| 403 | Q_UNUSED(newconfig); | - | ||||||||||||||||||||||||
| 404 | } | - | ||||||||||||||||||||||||
| 405 | - | |||||||||||||||||||||||||
| 406 | void QNetworkReplyHttpImpl::sslConfigurationImplementation(QSslConfiguration &configuration) const | - | ||||||||||||||||||||||||
| 407 | { | - | ||||||||||||||||||||||||
| 408 | Q_D(const QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 409 | configuration = d->sslConfiguration; | - | ||||||||||||||||||||||||
| 410 | } | - | ||||||||||||||||||||||||
| 411 | #endif | - | ||||||||||||||||||||||||
| 412 | - | |||||||||||||||||||||||||
| 413 | QNetworkReplyHttpImplPrivate::QNetworkReplyHttpImplPrivate() | - | ||||||||||||||||||||||||
| 414 | : QNetworkReplyPrivate() | - | ||||||||||||||||||||||||
| 415 | , manager(0) | - | ||||||||||||||||||||||||
| 416 | , managerPrivate(0) | - | ||||||||||||||||||||||||
| 417 | , synchronous(false) | - | ||||||||||||||||||||||||
| 418 | , state(Idle) | - | ||||||||||||||||||||||||
| 419 | , statusCode(0) | - | ||||||||||||||||||||||||
| 420 | , uploadByteDevicePosition(false) | - | ||||||||||||||||||||||||
| 421 | , uploadDeviceChoking(false) | - | ||||||||||||||||||||||||
| 422 | , outgoingData(0) | - | ||||||||||||||||||||||||
| 423 | , bytesUploaded(-1) | - | ||||||||||||||||||||||||
| 424 | , cacheLoadDevice(0) | - | ||||||||||||||||||||||||
| 425 | , loadingFromCache(false) | - | ||||||||||||||||||||||||
| 426 | , cacheSaveDevice(0) | - | ||||||||||||||||||||||||
| 427 | , cacheEnabled(false) | - | ||||||||||||||||||||||||
| 428 | , resumeOffset(0) | - | ||||||||||||||||||||||||
| 429 | , preMigrationDownloaded(-1) | - | ||||||||||||||||||||||||
| 430 | , bytesDownloaded(0) | - | ||||||||||||||||||||||||
| 431 | , bytesBuffered(0) | - | ||||||||||||||||||||||||
| 432 | , downloadBufferReadPosition(0) | - | ||||||||||||||||||||||||
| 433 | , downloadBufferCurrentSize(0) | - | ||||||||||||||||||||||||
| 434 | , downloadZerocopyBuffer(0) | - | ||||||||||||||||||||||||
| 435 | , pendingDownloadDataEmissions(QSharedPointer<QAtomicInt>::create()) | - | ||||||||||||||||||||||||
| 436 | , pendingDownloadProgressEmissions(QSharedPointer<QAtomicInt>::create()) | - | ||||||||||||||||||||||||
| 437 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 438 | , pendingIgnoreAllSslErrors(false) | - | ||||||||||||||||||||||||
| 439 | #endif | - | ||||||||||||||||||||||||
| 440 | - | |||||||||||||||||||||||||
| 441 | { | - | ||||||||||||||||||||||||
| 442 | } executed 887 times by 8 tests: end of blockExecuted by:
| 887 | ||||||||||||||||||||||||
| 443 | - | |||||||||||||||||||||||||
| 444 | QNetworkReplyHttpImplPrivate::~QNetworkReplyHttpImplPrivate() | - | ||||||||||||||||||||||||
| 445 | { | - | ||||||||||||||||||||||||
| 446 | } | - | ||||||||||||||||||||||||
| 447 | - | |||||||||||||||||||||||||
| 448 | /* | - | ||||||||||||||||||||||||
| 449 | For a given httpRequest | - | ||||||||||||||||||||||||
| 450 | 1) If AlwaysNetwork, return | - | ||||||||||||||||||||||||
| 451 | 2) If we have a cache entry for this url populate headers so the server can return 304 | - | ||||||||||||||||||||||||
| 452 | 3) Calculate if response_is_fresh and if so send the cache and set loadedFromCache to true | - | ||||||||||||||||||||||||
| 453 | */ | - | ||||||||||||||||||||||||
| 454 | bool QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(QHttpNetworkRequest &httpRequest) | - | ||||||||||||||||||||||||
| 455 | { | - | ||||||||||||||||||||||||
| 456 | QNetworkRequest::CacheLoadControl CacheLoadControlAttribute = | - | ||||||||||||||||||||||||
| 457 | (QNetworkRequest::CacheLoadControl)request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt(); | - | ||||||||||||||||||||||||
| 458 | if (CacheLoadControlAttribute == QNetworkRequest::AlwaysNetwork) { | - | ||||||||||||||||||||||||
| 459 | // If the request does not already specify preferred cache-control | - | ||||||||||||||||||||||||
| 460 | // force reload from the network and tell any caching proxy servers to reload too | - | ||||||||||||||||||||||||
| 461 | if (!request.rawHeaderList().contains("Cache-Control")) { | - | ||||||||||||||||||||||||
| 462 | httpRequest.setHeaderField("Cache-Control", "no-cache"); | - | ||||||||||||||||||||||||
| 463 | httpRequest.setHeaderField("Pragma", "no-cache"); | - | ||||||||||||||||||||||||
| 464 | } | - | ||||||||||||||||||||||||
| 465 | return false; | - | ||||||||||||||||||||||||
| 466 | } | - | ||||||||||||||||||||||||
| 467 | - | |||||||||||||||||||||||||
| 468 | // The disk cache API does not currently support partial content retrieval. | - | ||||||||||||||||||||||||
| 469 | // That is why we don't use the disk cache for any such requests. | - | ||||||||||||||||||||||||
| 470 | if (request.hasRawHeader("Range")) | - | ||||||||||||||||||||||||
| 471 | return false; | - | ||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | QAbstractNetworkCache *nc = managerPrivate->networkCache; | - | ||||||||||||||||||||||||
| 474 | if (!nc) | - | ||||||||||||||||||||||||
| 475 | return false; // no local cache | - | ||||||||||||||||||||||||
| 476 | - | |||||||||||||||||||||||||
| 477 | QNetworkCacheMetaData metaData = nc->metaData(httpRequest.url()); | - | ||||||||||||||||||||||||
| 478 | if (!metaData.isValid()) | - | ||||||||||||||||||||||||
| 479 | return false; // not in cache | - | ||||||||||||||||||||||||
| 480 | - | |||||||||||||||||||||||||
| 481 | if (!metaData.saveToDisk()) | - | ||||||||||||||||||||||||
| 482 | return false; | - | ||||||||||||||||||||||||
| 483 | - | |||||||||||||||||||||||||
| 484 | QNetworkHeadersPrivate cacheHeaders; | - | ||||||||||||||||||||||||
| 485 | QNetworkHeadersPrivate::RawHeadersList::ConstIterator it; | - | ||||||||||||||||||||||||
| 486 | cacheHeaders.setAllRawHeaders(metaData.rawHeaders()); | - | ||||||||||||||||||||||||
| 487 | - | |||||||||||||||||||||||||
| 488 | it = cacheHeaders.findRawHeader("etag"); | - | ||||||||||||||||||||||||
| 489 | if (it != cacheHeaders.rawHeaders.constEnd()) | - | ||||||||||||||||||||||||
| 490 | httpRequest.setHeaderField("If-None-Match", it->second); | - | ||||||||||||||||||||||||
| 491 | - | |||||||||||||||||||||||||
| 492 | QDateTime lastModified = metaData.lastModified(); | - | ||||||||||||||||||||||||
| 493 | if (lastModified.isValid()) | - | ||||||||||||||||||||||||
| 494 | httpRequest.setHeaderField("If-Modified-Since", QNetworkHeadersPrivate::toHttpDate(lastModified)); | - | ||||||||||||||||||||||||
| 495 | - | |||||||||||||||||||||||||
| 496 | it = cacheHeaders.findRawHeader("Cache-Control"); | - | ||||||||||||||||||||||||
| 497 | if (it != cacheHeaders.rawHeaders.constEnd()) { | - | ||||||||||||||||||||||||
| 498 | QHash<QByteArray, QByteArray> cacheControl = parseHttpOptionHeader(it->second); | - | ||||||||||||||||||||||||
| 499 | if (cacheControl.contains("must-revalidate")) | - | ||||||||||||||||||||||||
| 500 | return false; | - | ||||||||||||||||||||||||
| 501 | } | - | ||||||||||||||||||||||||
| 502 | - | |||||||||||||||||||||||||
| 503 | QDateTime currentDateTime = QDateTime::currentDateTimeUtc(); | - | ||||||||||||||||||||||||
| 504 | QDateTime expirationDate = metaData.expirationDate(); | - | ||||||||||||||||||||||||
| 505 | - | |||||||||||||||||||||||||
| 506 | bool response_is_fresh; | - | ||||||||||||||||||||||||
| 507 | if (!expirationDate.isValid()) { | - | ||||||||||||||||||||||||
| 508 | /* | - | ||||||||||||||||||||||||
| 509 | * age_value | - | ||||||||||||||||||||||||
| 510 | * is the value of Age: header received by the cache with | - | ||||||||||||||||||||||||
| 511 | * this response. | - | ||||||||||||||||||||||||
| 512 | * date_value | - | ||||||||||||||||||||||||
| 513 | * is the value of the origin server's Date: header | - | ||||||||||||||||||||||||
| 514 | * request_time | - | ||||||||||||||||||||||||
| 515 | * is the (local) time when the cache made the request | - | ||||||||||||||||||||||||
| 516 | * that resulted in this cached response | - | ||||||||||||||||||||||||
| 517 | * response_time | - | ||||||||||||||||||||||||
| 518 | * is the (local) time when the cache received the | - | ||||||||||||||||||||||||
| 519 | * response | - | ||||||||||||||||||||||||
| 520 | * now | - | ||||||||||||||||||||||||
| 521 | * is the current (local) time | - | ||||||||||||||||||||||||
| 522 | */ | - | ||||||||||||||||||||||||
| 523 | int age_value = 0; | - | ||||||||||||||||||||||||
| 524 | it = cacheHeaders.findRawHeader("age"); | - | ||||||||||||||||||||||||
| 525 | if (it != cacheHeaders.rawHeaders.constEnd()) | - | ||||||||||||||||||||||||
| 526 | age_value = it->second.toInt(); | - | ||||||||||||||||||||||||
| 527 | - | |||||||||||||||||||||||||
| 528 | QDateTime dateHeader; | - | ||||||||||||||||||||||||
| 529 | int date_value = 0; | - | ||||||||||||||||||||||||
| 530 | it = cacheHeaders.findRawHeader("date"); | - | ||||||||||||||||||||||||
| 531 | if (it != cacheHeaders.rawHeaders.constEnd()) { | - | ||||||||||||||||||||||||
| 532 | dateHeader = QNetworkHeadersPrivate::fromHttpDate(it->second); | - | ||||||||||||||||||||||||
| 533 | date_value = dateHeader.toTime_t(); | - | ||||||||||||||||||||||||
| 534 | } | - | ||||||||||||||||||||||||
| 535 | - | |||||||||||||||||||||||||
| 536 | int now = currentDateTime.toTime_t(); | - | ||||||||||||||||||||||||
| 537 | int request_time = now; | - | ||||||||||||||||||||||||
| 538 | int response_time = now; | - | ||||||||||||||||||||||||
| 539 | - | |||||||||||||||||||||||||
| 540 | // Algorithm from RFC 2616 section 13.2.3 | - | ||||||||||||||||||||||||
| 541 | int apparent_age = qMax(0, response_time - date_value); | - | ||||||||||||||||||||||||
| 542 | int corrected_received_age = qMax(apparent_age, age_value); | - | ||||||||||||||||||||||||
| 543 | int response_delay = response_time - request_time; | - | ||||||||||||||||||||||||
| 544 | int corrected_initial_age = corrected_received_age + response_delay; | - | ||||||||||||||||||||||||
| 545 | int resident_time = now - response_time; | - | ||||||||||||||||||||||||
| 546 | int current_age = corrected_initial_age + resident_time; | - | ||||||||||||||||||||||||
| 547 | - | |||||||||||||||||||||||||
| 548 | int freshness_lifetime = 0; | - | ||||||||||||||||||||||||
| 549 | - | |||||||||||||||||||||||||
| 550 | // RFC 2616 13.2.4 Expiration Calculations | - | ||||||||||||||||||||||||
| 551 | if (lastModified.isValid() && dateHeader.isValid()) { | - | ||||||||||||||||||||||||
| 552 | int diff = lastModified.secsTo(dateHeader); | - | ||||||||||||||||||||||||
| 553 | freshness_lifetime = diff / 10; | - | ||||||||||||||||||||||||
| 554 | if (httpRequest.headerField("Warning").isEmpty()) { | - | ||||||||||||||||||||||||
| 555 | QDateTime dt = currentDateTime.addSecs(current_age); | - | ||||||||||||||||||||||||
| 556 | if (currentDateTime.daysTo(dt) > 1) | - | ||||||||||||||||||||||||
| 557 | httpRequest.setHeaderField("Warning", "113"); | - | ||||||||||||||||||||||||
| 558 | } | - | ||||||||||||||||||||||||
| 559 | } | - | ||||||||||||||||||||||||
| 560 | - | |||||||||||||||||||||||||
| 561 | // the cache-saving code below sets the freshness_lifetime with (dateHeader - last_modified) / 10 | - | ||||||||||||||||||||||||
| 562 | // if "last-modified" is present, or to Expires otherwise | - | ||||||||||||||||||||||||
| 563 | response_is_fresh = (freshness_lifetime > current_age); | - | ||||||||||||||||||||||||
| 564 | } else { | - | ||||||||||||||||||||||||
| 565 | // expiration date was calculated earlier (e.g. when storing object to the cache) | - | ||||||||||||||||||||||||
| 566 | response_is_fresh = currentDateTime.secsTo(expirationDate) >= 0; | - | ||||||||||||||||||||||||
| 567 | } | - | ||||||||||||||||||||||||
| 568 | - | |||||||||||||||||||||||||
| 569 | if (!response_is_fresh) | - | ||||||||||||||||||||||||
| 570 | return false; | - | ||||||||||||||||||||||||
| 571 | - | |||||||||||||||||||||||||
| 572 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||||||||
| 573 | qDebug() << "response_is_fresh" << CacheLoadControlAttribute; | - | ||||||||||||||||||||||||
| 574 | #endif | - | ||||||||||||||||||||||||
| 575 | return sendCacheContents(metaData); | - | ||||||||||||||||||||||||
| 576 | } | - | ||||||||||||||||||||||||
| 577 | - | |||||||||||||||||||||||||
| 578 | QHttpNetworkRequest::Priority QNetworkReplyHttpImplPrivate::convert(const QNetworkRequest::Priority& prio) | - | ||||||||||||||||||||||||
| 579 | { | - | ||||||||||||||||||||||||
| 580 | switch (prio) { | - | ||||||||||||||||||||||||
| 581 | case QNetworkRequest::LowPriority: | - | ||||||||||||||||||||||||
| 582 | return QHttpNetworkRequest::LowPriority; | - | ||||||||||||||||||||||||
| 583 | case QNetworkRequest::HighPriority: | - | ||||||||||||||||||||||||
| 584 | return QHttpNetworkRequest::HighPriority; | - | ||||||||||||||||||||||||
| 585 | case QNetworkRequest::NormalPriority: | - | ||||||||||||||||||||||||
| 586 | default: | - | ||||||||||||||||||||||||
| 587 | return QHttpNetworkRequest::NormalPriority; | - | ||||||||||||||||||||||||
| 588 | } | - | ||||||||||||||||||||||||
| 589 | } | - | ||||||||||||||||||||||||
| 590 | - | |||||||||||||||||||||||||
| 591 | void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpRequest) | - | ||||||||||||||||||||||||
| 592 | { | - | ||||||||||||||||||||||||
| 593 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 594 | - | |||||||||||||||||||||||||
| 595 | QThread *thread = 0; | - | ||||||||||||||||||||||||
| 596 | if (synchronous) {
| 76-814 | ||||||||||||||||||||||||
| 597 | // A synchronous HTTP request uses its own thread | - | ||||||||||||||||||||||||
| 598 | thread = new QThread(); | - | ||||||||||||||||||||||||
| 599 | thread->setObjectName(QStringLiteral("Qt HTTP synchronous thread")); | - | ||||||||||||||||||||||||
| 600 | QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); | - | ||||||||||||||||||||||||
| 601 | thread->start(); | - | ||||||||||||||||||||||||
| 602 | } else if (!managerPrivate->httpThread) { executed 76 times by 1 test: end of blockExecuted by:
| 76-471 | ||||||||||||||||||||||||
| 603 | // We use the manager-global thread. | - | ||||||||||||||||||||||||
| 604 | // At some point we could switch to having multiple threads if it makes sense. | - | ||||||||||||||||||||||||
| 605 | managerPrivate->httpThread = new QThread(); | - | ||||||||||||||||||||||||
| 606 | managerPrivate->httpThread->setObjectName(QStringLiteral("Qt HTTP thread")); executed 471 times by 8 tests: return qstring_literal_temp;Executed by:
| 471 | ||||||||||||||||||||||||
| 607 | managerPrivate->httpThread->start(); | - | ||||||||||||||||||||||||
| 608 | - | |||||||||||||||||||||||||
| 609 | thread = managerPrivate->httpThread; | - | ||||||||||||||||||||||||
| 610 | } else { executed 471 times by 8 tests: end of blockExecuted by:
| 471 | ||||||||||||||||||||||||
| 611 | // Asynchronous request, thread already exists | - | ||||||||||||||||||||||||
| 612 | thread = managerPrivate->httpThread; | - | ||||||||||||||||||||||||
| 613 | } executed 343 times by 4 tests: end of blockExecuted by:
| 343 | ||||||||||||||||||||||||
| 614 | - | |||||||||||||||||||||||||
| 615 | QUrl url = newHttpRequest.url(); | - | ||||||||||||||||||||||||
| 616 | httpRequest.setUrl(url); | - | ||||||||||||||||||||||||
| 617 | httpRequest.setRedirectCount(newHttpRequest.maximumRedirectsAllowed()); | - | ||||||||||||||||||||||||
| 618 | - | |||||||||||||||||||||||||
| 619 | QString scheme = url.scheme(); | - | ||||||||||||||||||||||||
| 620 | bool ssl = (scheme == QLatin1String("https")
| 231-659 | ||||||||||||||||||||||||
| 621 | || scheme == QLatin1String("preconnect-https"));
| 0-659 | ||||||||||||||||||||||||
| 622 | q->setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, ssl); | - | ||||||||||||||||||||||||
| 623 | httpRequest.setSsl(ssl); | - | ||||||||||||||||||||||||
| 624 | - | |||||||||||||||||||||||||
| 625 | bool preConnect = (scheme == QLatin1String("preconnect-http")
| 0-890 | ||||||||||||||||||||||||
| 626 | || scheme == QLatin1String("preconnect-https"));
| 0-890 | ||||||||||||||||||||||||
| 627 | httpRequest.setPreConnect(preConnect); | - | ||||||||||||||||||||||||
| 628 | - | |||||||||||||||||||||||||
| 629 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||||||||
| 630 | QNetworkProxy transparentProxy, cacheProxy; | - | ||||||||||||||||||||||||
| 631 | - | |||||||||||||||||||||||||
| 632 | // FIXME the proxy stuff should be done in the HTTP thread | - | ||||||||||||||||||||||||
| 633 | foreach (const QNetworkProxyauto &p,proxies = managerPrivate->queryProxy(QNetworkProxyQuery(newHttpRequest.url())))())); | - | ||||||||||||||||||||||||
| 634 | for (const QNetworkProxy &p : proxies) { | - | ||||||||||||||||||||||||
| 635 | // use the first proxy that works | - | ||||||||||||||||||||||||
| 636 | // for non-encrypted connections, any transparent or HTTP proxy | - | ||||||||||||||||||||||||
| 637 | // for encrypted, only transparent proxies | - | ||||||||||||||||||||||||
| 638 | if (!ssl
| 234-661 | ||||||||||||||||||||||||
| 639 | && (p.capabilities() & QNetworkProxy::CachingCapability) | - | ||||||||||||||||||||||||
| 640 | && (p.type() == QNetworkProxy::HttpProxy ||
| 11-47 | ||||||||||||||||||||||||
| 641 | p.type() == QNetworkProxy::HttpCachingProxy)) {
| 3-8 | ||||||||||||||||||||||||
| 642 | cacheProxy = p; | - | ||||||||||||||||||||||||
| 643 | transparentProxy = QNetworkProxy::NoProxy; | - | ||||||||||||||||||||||||
| 644 | break; executed 55 times by 1 test: break;Executed by:
| 55 | ||||||||||||||||||||||||
| 645 | } | - | ||||||||||||||||||||||||
| 646 | if (p.isTransparentProxy()) {
| 8-832 | ||||||||||||||||||||||||
| 647 | transparentProxy = p; | - | ||||||||||||||||||||||||
| 648 | cacheProxy = QNetworkProxy::NoProxy; | - | ||||||||||||||||||||||||
| 649 | break; executed 832 times by 8 tests: break;Executed by:
| 832 | ||||||||||||||||||||||||
| 650 | } | - | ||||||||||||||||||||||||
| 651 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 652 | - | |||||||||||||||||||||||||
| 653 | // check if at least one of the proxies | - | ||||||||||||||||||||||||
| 654 | if (transparentProxy.type() == QNetworkProxy::DefaultProxy &&
| 3-887 | ||||||||||||||||||||||||
| 655 | cacheProxy.type() == QNetworkProxy::DefaultProxy) {
| 0-3 | ||||||||||||||||||||||||
| 656 | // unsuitable proxies | - | ||||||||||||||||||||||||
| 657 | QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, | - | ||||||||||||||||||||||||
| 658 | Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ProxyNotFoundError), | - | ||||||||||||||||||||||||
| 659 | Q_ARG(QString, QNetworkReplyHttpImpl::tr("No suitable proxy found"))); | - | ||||||||||||||||||||||||
| 660 | QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 661 | return; executed 3 times by 1 test: return;Executed by:
| 3 | ||||||||||||||||||||||||
| 662 | } | - | ||||||||||||||||||||||||
| 663 | #endif | - | ||||||||||||||||||||||||
| 664 | - | |||||||||||||||||||||||||
| 665 | if (newHttpRequest.attribute(QNetworkRequest::FollowRedirectsAttribute).toBool())
| 9-878 | ||||||||||||||||||||||||
| 666 | httpRequest.setFollowRedirects(true); executed 9 times by 1 test: httpRequest.setFollowRedirects(true);Executed by:
| 9 | ||||||||||||||||||||||||
| 667 | - | |||||||||||||||||||||||||
| 668 | httpRequest.setPriority(convert(newHttpRequest.priority())); | - | ||||||||||||||||||||||||
| 669 | - | |||||||||||||||||||||||||
| 670 | switch (operation) { | - | ||||||||||||||||||||||||
| 671 | case QNetworkAccessManager::GetOperation: executed 654 times by 7 tests: case QNetworkAccessManager::GetOperation:Executed by:
| 654 | ||||||||||||||||||||||||
| 672 | httpRequest.setOperation(QHttpNetworkRequest::Get); | - | ||||||||||||||||||||||||
| 673 | if (loadFromCacheIfAllowed(httpRequest))
| 18-636 | ||||||||||||||||||||||||
| 674 | return; // no need to send the request! :) executed 18 times by 2 tests: return;Executed by:
| 18 | ||||||||||||||||||||||||
| 675 | break; executed 636 times by 7 tests: break;Executed by:
| 636 | ||||||||||||||||||||||||
| 676 | - | |||||||||||||||||||||||||
| 677 | case QNetworkAccessManager::HeadOperation: executed 26 times by 1 test: case QNetworkAccessManager::HeadOperation:Executed by:
| 26 | ||||||||||||||||||||||||
| 678 | httpRequest.setOperation(QHttpNetworkRequest::Head); | - | ||||||||||||||||||||||||
| 679 | if (loadFromCacheIfAllowed(httpRequest))
| 0-26 | ||||||||||||||||||||||||
| 680 | return; // no need to send the request! :) never executed: return; | 0 | ||||||||||||||||||||||||
| 681 | break; executed 26 times by 1 test: break;Executed by:
| 26 | ||||||||||||||||||||||||
| 682 | - | |||||||||||||||||||||||||
| 683 | case QNetworkAccessManager::PostOperation: executed 157 times by 3 tests: case QNetworkAccessManager::PostOperation:Executed by:
| 157 | ||||||||||||||||||||||||
| 684 | invalidateCache(); | - | ||||||||||||||||||||||||
| 685 | httpRequest.setOperation(QHttpNetworkRequest::Post); | - | ||||||||||||||||||||||||
| 686 | createUploadByteDevice(); | - | ||||||||||||||||||||||||
| 687 | break; executed 157 times by 3 tests: break;Executed by:
| 157 | ||||||||||||||||||||||||
| 688 | - | |||||||||||||||||||||||||
| 689 | case QNetworkAccessManager::PutOperation: executed 36 times by 2 tests: case QNetworkAccessManager::PutOperation:Executed by:
| 36 | ||||||||||||||||||||||||
| 690 | invalidateCache(); | - | ||||||||||||||||||||||||
| 691 | httpRequest.setOperation(QHttpNetworkRequest::Put); | - | ||||||||||||||||||||||||
| 692 | createUploadByteDevice(); | - | ||||||||||||||||||||||||
| 693 | break; executed 36 times by 2 tests: break;Executed by:
| 36 | ||||||||||||||||||||||||
| 694 | - | |||||||||||||||||||||||||
| 695 | case QNetworkAccessManager::DeleteOperation: executed 7 times by 1 test: case QNetworkAccessManager::DeleteOperation:Executed by:
| 7 | ||||||||||||||||||||||||
| 696 | invalidateCache(); | - | ||||||||||||||||||||||||
| 697 | httpRequest.setOperation(QHttpNetworkRequest::Delete); | - | ||||||||||||||||||||||||
| 698 | break; executed 7 times by 1 test: break;Executed by:
| 7 | ||||||||||||||||||||||||
| 699 | - | |||||||||||||||||||||||||
| 700 | case QNetworkAccessManager::CustomOperation: executed 7 times by 1 test: case QNetworkAccessManager::CustomOperation:Executed by:
| 7 | ||||||||||||||||||||||||
| 701 | invalidateCache(); // for safety reasons, we don't know what the operation does | - | ||||||||||||||||||||||||
| 702 | httpRequest.setOperation(QHttpNetworkRequest::Custom); | - | ||||||||||||||||||||||||
| 703 | createUploadByteDevice(); | - | ||||||||||||||||||||||||
| 704 | httpRequest.setCustomVerb(newHttpRequest.attribute( | - | ||||||||||||||||||||||||
| 705 | QNetworkRequest::CustomVerbAttribute).toByteArray()); | - | ||||||||||||||||||||||||
| 706 | break; executed 7 times by 1 test: break;Executed by:
| 7 | ||||||||||||||||||||||||
| 707 | - | |||||||||||||||||||||||||
| 708 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 709 | break; // can't happen never executed: break; | 0 | ||||||||||||||||||||||||
| 710 | } | - | ||||||||||||||||||||||||
| 711 | - | |||||||||||||||||||||||||
| 712 | QList<QByteArray> headers = newHttpRequest.rawHeaderList(); | - | ||||||||||||||||||||||||
| 713 | if (resumeOffset != 0) {
| 0-869 | ||||||||||||||||||||||||
| 714 | ifconst (int rangeIndex = headers.containsindexOf("Range"))); | - | ||||||||||||||||||||||||
| 715 | if (rangeIndex != -1)
| 0 | ||||||||||||||||||||||||
| 716 | // Need to adjust resume offset for user specified range | - | ||||||||||||||||||||||||
| 717 | - | |||||||||||||||||||||||||
| 718 | headers.removeOneremoveAt("Range"rangeIndex); | - | ||||||||||||||||||||||||
| 719 | - | |||||||||||||||||||||||||
| 720 | // We've already verified that requestRange starts with "bytes=", see canResume. | - | ||||||||||||||||||||||||
| 721 | QByteArray requestRange = newHttpRequest.rawHeader("Range").mid(6); | - | ||||||||||||||||||||||||
| 722 | - | |||||||||||||||||||||||||
| 723 | int index = requestRange.indexOf('-'); | - | ||||||||||||||||||||||||
| 724 | - | |||||||||||||||||||||||||
| 725 | quint64 requestStartOffset = requestRange.left(index).toULongLong(); | - | ||||||||||||||||||||||||
| 726 | quint64 requestEndOffset = requestRange.mid(index + 1).toULongLong(); | - | ||||||||||||||||||||||||
| 727 | - | |||||||||||||||||||||||||
| 728 | requestRange = "bytes=" + QByteArray::number(resumeOffset + requestStartOffset) + | - | ||||||||||||||||||||||||
| 729 | '-' + QByteArray::number(requestEndOffset); | - | ||||||||||||||||||||||||
| 730 | - | |||||||||||||||||||||||||
| 731 | httpRequest.setHeaderField("Range", requestRange); | - | ||||||||||||||||||||||||
| 732 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 733 | httpRequest.setHeaderField("Range", "bytes=" + QByteArray::number(resumeOffset) + '-'); | - | ||||||||||||||||||||||||
| 734 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 735 | } | - | ||||||||||||||||||||||||
| 736 | - | |||||||||||||||||||||||||
| 737 | foreachfor (const QByteArray &header, : qAsConst(headers))) | - | ||||||||||||||||||||||||
| 738 | httpRequest.setHeaderField(header, newHttpRequest.rawHeader(header)); executed 319 times by 3 tests: httpRequest.setHeaderField(header, newHttpRequest.rawHeader(header));Executed by:
| 319 | ||||||||||||||||||||||||
| 739 | - | |||||||||||||||||||||||||
| 740 | if (newHttpRequest.attribute(QNetworkRequest::HttpPipeliningAllowedAttribute).toBool())
| 20-849 | ||||||||||||||||||||||||
| 741 | httpRequest.setPipeliningAllowed(true); executed 20 times by 1 test: httpRequest.setPipeliningAllowed(true);Executed by:
| 20 | ||||||||||||||||||||||||
| 742 | - | |||||||||||||||||||||||||
| 743 | if (request.attribute(QNetworkRequest::SpdyAllowedAttribute).toBool())
| 113-756 | ||||||||||||||||||||||||
| 744 | httpRequest.setSPDYAllowed(true); executed 113 times by 1 test: httpRequest.setSPDYAllowed(true);Executed by:
| 113 | ||||||||||||||||||||||||
| 745 | - | |||||||||||||||||||||||||
| 746 | if (static_cast<QNetworkRequest::LoadControl>
| 1-868 | ||||||||||||||||||||||||
| 747 | (newHttpRequest.attribute(QNetworkRequest::AuthenticationReuseAttribute,
| 1-868 | ||||||||||||||||||||||||
| 748 | QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Manual)
| 1-868 | ||||||||||||||||||||||||
| 749 | httpRequest.setWithCredentials(false); executed 1 time by 1 test: httpRequest.setWithCredentials(false);Executed by:
| 1 | ||||||||||||||||||||||||
| 750 | - | |||||||||||||||||||||||||
| 751 | if (request.attribute(QNetworkRequest::EmitAllUploadProgressSignalsAttribute).toBool())
| 1-868 | ||||||||||||||||||||||||
| 752 | emitAllUploadProgressSignals = true; executed 1 time by 1 test: emitAllUploadProgressSignals = true;Executed by:
| 1 | ||||||||||||||||||||||||
| 753 | - | |||||||||||||||||||||||||
| 754 | - | |||||||||||||||||||||||||
| 755 | // Create the HTTP thread delegate | - | ||||||||||||||||||||||||
| 756 | QHttpThreadDelegate *delegate = new QHttpThreadDelegate; | - | ||||||||||||||||||||||||
| 757 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||||||||
| 758 | delegate->networkSession = managerPrivate->getNetworkSession(); | - | ||||||||||||||||||||||||
| 759 | #endif | - | ||||||||||||||||||||||||
| 760 | - | |||||||||||||||||||||||||
| 761 | // For the synchronous HTTP, this is the normal way the delegate gets deleted | - | ||||||||||||||||||||||||
| 762 | // For the asynchronous HTTP this is a safety measure, the delegate deletes itself when HTTP is finished | - | ||||||||||||||||||||||||
| 763 | QObject::connect(thread, SIGNAL(finished()), delegate, SLOT(deleteLater())); | - | ||||||||||||||||||||||||
| 764 | - | |||||||||||||||||||||||||
| 765 | // Set the properties it needs | - | ||||||||||||||||||||||||
| 766 | delegate->httpRequest = httpRequest; | - | ||||||||||||||||||||||||
| 767 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||||||||
| 768 | delegate->cacheProxy = cacheProxy; | - | ||||||||||||||||||||||||
| 769 | delegate->transparentProxy = transparentProxy; | - | ||||||||||||||||||||||||
| 770 | #endif | - | ||||||||||||||||||||||||
| 771 | delegate->ssl = ssl; | - | ||||||||||||||||||||||||
| 772 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 773 | if (ssl)
| 229-640 | ||||||||||||||||||||||||
| 774 | delegate->incomingSslConfiguration = newHttpRequest.sslConfiguration(); executed 229 times by 2 tests: delegate->incomingSslConfiguration = newHttpRequest.sslConfiguration();Executed by:
| 229 | ||||||||||||||||||||||||
| 775 | #endif | - | ||||||||||||||||||||||||
| 776 | - | |||||||||||||||||||||||||
| 777 | // Do we use synchronous HTTP? | - | ||||||||||||||||||||||||
| 778 | delegate->synchronous = synchronous; | - | ||||||||||||||||||||||||
| 779 | - | |||||||||||||||||||||||||
| 780 | // The authentication manager is used to avoid the BlockingQueuedConnection communication | - | ||||||||||||||||||||||||
| 781 | // from HTTP thread to user thread in some cases. | - | ||||||||||||||||||||||||
| 782 | delegate->authenticationManager = managerPrivate->authenticationManager; | - | ||||||||||||||||||||||||
| 783 | - | |||||||||||||||||||||||||
| 784 | if (!synchronous) {
| 76-793 | ||||||||||||||||||||||||
| 785 | // Tell our zerocopy policy to the delegate | - | ||||||||||||||||||||||||
| 786 | QVariant downloadBufferMaximumSizeAttribute = newHttpRequest.attribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute); | - | ||||||||||||||||||||||||
| 787 | if (downloadBufferMaximumSizeAttribute.isValid()) {
| 7-786 | ||||||||||||||||||||||||
| 788 | delegate->downloadBufferMaximumSize = downloadBufferMaximumSizeAttribute.toLongLong(); | - | ||||||||||||||||||||||||
| 789 | } else { executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||||||||
| 790 | // If there is no MaximumDownloadBufferSizeAttribute set (which is for the majority | - | ||||||||||||||||||||||||
| 791 | // of QNetworkRequest) then we can assume we'll do it anyway for small HTTP replies. | - | ||||||||||||||||||||||||
| 792 | // This helps with performance and memory fragmentation. | - | ||||||||||||||||||||||||
| 793 | delegate->downloadBufferMaximumSize = 128*1024; | - | ||||||||||||||||||||||||
| 794 | } executed 786 times by 8 tests: end of blockExecuted by:
| 786 | ||||||||||||||||||||||||
| 795 | - | |||||||||||||||||||||||||
| 796 | - | |||||||||||||||||||||||||
| 797 | // These atomic integers are used for signal compression | - | ||||||||||||||||||||||||
| 798 | delegate->pendingDownloadData = pendingDownloadDataEmissions; | - | ||||||||||||||||||||||||
| 799 | delegate->pendingDownloadProgress = pendingDownloadProgressEmissions; | - | ||||||||||||||||||||||||
| 800 | - | |||||||||||||||||||||||||
| 801 | // Connect the signals of the delegate to us | - | ||||||||||||||||||||||||
| 802 | QObject::connect(delegate, SIGNAL(downloadData(QByteArray)), | - | ||||||||||||||||||||||||
| 803 | q, SLOT(replyDownloadData(QByteArray)), | - | ||||||||||||||||||||||||
| 804 | Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 805 | QObject::connect(delegate, SIGNAL(downloadFinished()), | - | ||||||||||||||||||||||||
| 806 | q, SLOT(replyFinished()), | - | ||||||||||||||||||||||||
| 807 | Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 808 | QObject::connect(delegate, SIGNAL(downloadMetaData(QList<QPair<QByteArray,QByteArray> >, | - | ||||||||||||||||||||||||
| 809 | int, QString, bool, | - | ||||||||||||||||||||||||
| 810 | QSharedPointer<char>, qint64, bool)), | - | ||||||||||||||||||||||||
| 811 | q, SLOT(replyDownloadMetaData(QList<QPair<QByteArray,QByteArray> >, | - | ||||||||||||||||||||||||
| 812 | int, QString, bool, | - | ||||||||||||||||||||||||
| 813 | QSharedPointer<char>, qint64, bool)), | - | ||||||||||||||||||||||||
| 814 | Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 815 | QObject::connect(delegate, SIGNAL(downloadProgress(qint64,qint64)), | - | ||||||||||||||||||||||||
| 816 | q, SLOT(replyDownloadProgressSlot(qint64,qint64)), | - | ||||||||||||||||||||||||
| 817 | Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 818 | QObject::connect(delegate, SIGNAL(error(QNetworkReply::NetworkError,QString)), | - | ||||||||||||||||||||||||
| 819 | q, SLOT(httpError(QNetworkReply::NetworkError,QString)), | - | ||||||||||||||||||||||||
| 820 | Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 821 | QObject::connect(delegate, SIGNAL(redirected(QUrl,int,int)), | - | ||||||||||||||||||||||||
| 822 | q, SLOT(onRedirected(QUrl,int,int)), | - | ||||||||||||||||||||||||
| 823 | Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 824 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 825 | QObject::connect(delegate, SIGNAL(sslConfigurationChanged(QSslConfiguration)), | - | ||||||||||||||||||||||||
| 826 | q, SLOT(replySslConfigurationChanged(QSslConfiguration)), | - | ||||||||||||||||||||||||
| 827 | Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 828 | #endif | - | ||||||||||||||||||||||||
| 829 | // Those need to report back, therefire BlockingQueuedConnection | - | ||||||||||||||||||||||||
| 830 | QObject::connect(delegate, SIGNAL(authenticationRequired(QHttpNetworkRequest,QAuthenticator*)), | - | ||||||||||||||||||||||||
| 831 | q, SLOT(httpAuthenticationRequired(QHttpNetworkRequest,QAuthenticator*)), | - | ||||||||||||||||||||||||
| 832 | Qt::BlockingQueuedConnection); | - | ||||||||||||||||||||||||
| 833 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||||||||
| 834 | QObject::connect(delegate, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), | - | ||||||||||||||||||||||||
| 835 | q, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), | - | ||||||||||||||||||||||||
| 836 | Qt::BlockingQueuedConnection); | - | ||||||||||||||||||||||||
| 837 | #endif | - | ||||||||||||||||||||||||
| 838 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 839 | QObject::connect(delegate, SIGNAL(encrypted()), q, SLOT(replyEncrypted()), | - | ||||||||||||||||||||||||
| 840 | Qt::BlockingQueuedConnection); | - | ||||||||||||||||||||||||
| 841 | QObject::connect(delegate, SIGNAL(sslErrors(QList<QSslError>,bool*,QList<QSslError>*)), | - | ||||||||||||||||||||||||
| 842 | q, SLOT(replySslErrors(QList<QSslError>,bool*,QList<QSslError>*)), | - | ||||||||||||||||||||||||
| 843 | Qt::BlockingQueuedConnection); | - | ||||||||||||||||||||||||
| 844 | QObject::connect(delegate, SIGNAL(preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)), | - | ||||||||||||||||||||||||
| 845 | q, SLOT(replyPreSharedKeyAuthenticationRequiredSlot(QSslPreSharedKeyAuthenticator*)), | - | ||||||||||||||||||||||||
| 846 | Qt::BlockingQueuedConnection); | - | ||||||||||||||||||||||||
| 847 | #endif | - | ||||||||||||||||||||||||
| 848 | // This signal we will use to start the request. | - | ||||||||||||||||||||||||
| 849 | QObject::connect(q, SIGNAL(startHttpRequest()), delegate, SLOT(startRequest())); | - | ||||||||||||||||||||||||
| 850 | QObject::connect(q, SIGNAL(abortHttpRequest()), delegate, SLOT(abortRequest())); | - | ||||||||||||||||||||||||
| 851 | - | |||||||||||||||||||||||||
| 852 | // To throttle the connection. | - | ||||||||||||||||||||||||
| 853 | QObject::connect(q, SIGNAL(readBufferSizeChanged(qint64)), delegate, SLOT(readBufferSizeChanged(qint64))); | - | ||||||||||||||||||||||||
| 854 | QObject::connect(q, SIGNAL(readBufferFreed(qint64)), delegate, SLOT(readBufferFreed(qint64))); | - | ||||||||||||||||||||||||
| 855 | - | |||||||||||||||||||||||||
| 856 | if (uploadByteDevice) {
| 155-638 | ||||||||||||||||||||||||
| 857 | QNonContiguousByteDeviceThreadForwardImpl *forwardUploadDevice = | - | ||||||||||||||||||||||||
| 858 | new QNonContiguousByteDeviceThreadForwardImpl(uploadByteDevice->atEnd(), uploadByteDevice->size()); | - | ||||||||||||||||||||||||
| 859 | forwardUploadDevice->setParent(delegate); // needed to make sure it is moved on moveToThread() | - | ||||||||||||||||||||||||
| 860 | delegate->httpRequest.setUploadByteDevice(forwardUploadDevice); | - | ||||||||||||||||||||||||
| 861 | - | |||||||||||||||||||||||||
| 862 | // If the device in the user thread claims it has more data, keep the flow to HTTP thread going | - | ||||||||||||||||||||||||
| 863 | QObject::connect(uploadByteDevice.data(), SIGNAL(readyRead()), | - | ||||||||||||||||||||||||
| 864 | q, SLOT(uploadByteDeviceReadyReadSlot()), | - | ||||||||||||||||||||||||
| 865 | Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 866 | - | |||||||||||||||||||||||||
| 867 | // From user thread to http thread: | - | ||||||||||||||||||||||||
| 868 | QObject::connect(q, SIGNAL(haveUploadData(qint64,QByteArray,bool,qint64)), | - | ||||||||||||||||||||||||
| 869 | forwardUploadDevice, SLOT(haveDataSlot(qint64,QByteArray,bool,qint64)), Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 870 | QObject::connect(uploadByteDevice.data(), SIGNAL(readyRead()), | - | ||||||||||||||||||||||||
| 871 | forwardUploadDevice, SIGNAL(readyRead()), | - | ||||||||||||||||||||||||
| 872 | Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 873 | - | |||||||||||||||||||||||||
| 874 | // From http thread to user thread: | - | ||||||||||||||||||||||||
| 875 | QObject::connect(forwardUploadDevice, SIGNAL(wantData(qint64)), | - | ||||||||||||||||||||||||
| 876 | q, SLOT(wantUploadDataSlot(qint64))); | - | ||||||||||||||||||||||||
| 877 | QObject::connect(forwardUploadDevice,SIGNAL(processedData(qint64, qint64)), | - | ||||||||||||||||||||||||
| 878 | q, SLOT(sentUploadDataSlot(qint64,qint64))); | - | ||||||||||||||||||||||||
| 879 | QObject::connect(forwardUploadDevice, SIGNAL(resetData(bool*)), | - | ||||||||||||||||||||||||
| 880 | q, SLOT(resetUploadDataSlot(bool*)), | - | ||||||||||||||||||||||||
| 881 | Qt::BlockingQueuedConnection); // this is the only one with BlockingQueued! | - | ||||||||||||||||||||||||
| 882 | } executed 155 times by 3 tests: end of blockExecuted by:
| 155 | ||||||||||||||||||||||||
| 883 | } else if (synchronous) { executed 793 times by 8 tests: end of blockExecuted by:
| 0-793 | ||||||||||||||||||||||||
| 884 | QObject::connect(q, SIGNAL(startHttpRequestSynchronously()), delegate, SLOT(startRequestSynchronously()), Qt::BlockingQueuedConnection); | - | ||||||||||||||||||||||||
| 885 | - | |||||||||||||||||||||||||
| 886 | if (uploadByteDevice) {
| 35-41 | ||||||||||||||||||||||||
| 887 | // For the synchronous HTTP use case the use thread (this one here) is blocked | - | ||||||||||||||||||||||||
| 888 | // so we cannot use the asynchronous upload architecture. | - | ||||||||||||||||||||||||
| 889 | // We therefore won't use the QNonContiguousByteDeviceThreadForwardImpl but directly | - | ||||||||||||||||||||||||
| 890 | // use the uploadByteDevice provided to us by the QNetworkReplyImpl. | - | ||||||||||||||||||||||||
| 891 | // The code that is in start() makes sure it is safe to use from a thread | - | ||||||||||||||||||||||||
| 892 | // since it only wraps a QRingBuffer | - | ||||||||||||||||||||||||
| 893 | delegate->httpRequest.setUploadByteDevice(uploadByteDevice.data()); | - | ||||||||||||||||||||||||
| 894 | } executed 41 times by 1 test: end of blockExecuted by:
| 41 | ||||||||||||||||||||||||
| 895 | } executed 76 times by 1 test: end of blockExecuted by:
| 76 | ||||||||||||||||||||||||
| 896 | - | |||||||||||||||||||||||||
| 897 | - | |||||||||||||||||||||||||
| 898 | // Move the delegate to the http thread | - | ||||||||||||||||||||||||
| 899 | delegate->moveToThread(thread); | - | ||||||||||||||||||||||||
| 900 | // This call automatically moves the uploadDevice too for the asynchronous case. | - | ||||||||||||||||||||||||
| 901 | - | |||||||||||||||||||||||||
| 902 | // Prepare timers for progress notifications | - | ||||||||||||||||||||||||
| 903 | downloadProgressSignalChoke.start(); | - | ||||||||||||||||||||||||
| 904 | uploadProgressSignalChoke.invalidate(); | - | ||||||||||||||||||||||||
| 905 | - | |||||||||||||||||||||||||
| 906 | // Send an signal to the delegate so it starts working in the other thread | - | ||||||||||||||||||||||||
| 907 | if (synchronous) {
| 76-793 | ||||||||||||||||||||||||
| 908 | emit q->startHttpRequestSynchronously(); // This one is BlockingQueuedConnection, so it will return when all work is done | - | ||||||||||||||||||||||||
| 909 | - | |||||||||||||||||||||||||
| 910 | if (delegate->incomingErrorCode != QNetworkReply::NoError) {
| 13-63 | ||||||||||||||||||||||||
| 911 | replyDownloadMetaData | - | ||||||||||||||||||||||||
| 912 | (delegate->incomingHeaders, | - | ||||||||||||||||||||||||
| 913 | delegate->incomingStatusCode, | - | ||||||||||||||||||||||||
| 914 | delegate->incomingReasonPhrase, | - | ||||||||||||||||||||||||
| 915 | delegate->isPipeliningUsed, | - | ||||||||||||||||||||||||
| 916 | QSharedPointer<char>(), | - | ||||||||||||||||||||||||
| 917 | delegate->incomingContentLength, | - | ||||||||||||||||||||||||
| 918 | delegate->isSpdyUsed); | - | ||||||||||||||||||||||||
| 919 | replyDownloadData(delegate->synchronousDownloadData); | - | ||||||||||||||||||||||||
| 920 | httpError(delegate->incomingErrorCode, delegate->incomingErrorDetail); | - | ||||||||||||||||||||||||
| 921 | } else { executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 922 | replyDownloadMetaData | - | ||||||||||||||||||||||||
| 923 | (delegate->incomingHeaders, | - | ||||||||||||||||||||||||
| 924 | delegate->incomingStatusCode, | - | ||||||||||||||||||||||||
| 925 | delegate->incomingReasonPhrase, | - | ||||||||||||||||||||||||
| 926 | delegate->isPipeliningUsed, | - | ||||||||||||||||||||||||
| 927 | QSharedPointer<char>(), | - | ||||||||||||||||||||||||
| 928 | delegate->incomingContentLength, | - | ||||||||||||||||||||||||
| 929 | delegate->isSpdyUsed); | - | ||||||||||||||||||||||||
| 930 | replyDownloadData(delegate->synchronousDownloadData); | - | ||||||||||||||||||||||||
| 931 | } executed 63 times by 1 test: end of blockExecuted by:
| 63 | ||||||||||||||||||||||||
| 932 | - | |||||||||||||||||||||||||
| 933 | thread->quit(); | - | ||||||||||||||||||||||||
| 934 | thread->wait(5000); | - | ||||||||||||||||||||||||
| 935 | if (thread->isFinished())
| 0-76 | ||||||||||||||||||||||||
| 936 | delete thread; executed 76 times by 1 test: delete thread;Executed by:
| 76 | ||||||||||||||||||||||||
| 937 | else | - | ||||||||||||||||||||||||
| 938 | QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); never executed: QObject::connect(thread, qFlagLocation("2""finished()" "\0" __FILE__ ":" "938"), thread, qFlagLocation("1""deleteLater()" "\0" __FILE__ ":" "938")); | 0 | ||||||||||||||||||||||||
| 939 | - | |||||||||||||||||||||||||
| 940 | finished(); | - | ||||||||||||||||||||||||
| 941 | } else { executed 76 times by 1 test: end of blockExecuted by:
| 76 | ||||||||||||||||||||||||
| 942 | emit q->startHttpRequest(); // Signal to the HTTP thread and go back to user. | - | ||||||||||||||||||||||||
| 943 | } executed 793 times by 8 tests: end of blockExecuted by:
| 793 | ||||||||||||||||||||||||
| 944 | } | - | ||||||||||||||||||||||||
| 945 | - | |||||||||||||||||||||||||
| 946 | void QNetworkReplyHttpImplPrivate::invalidateCache() | - | ||||||||||||||||||||||||
| 947 | { | - | ||||||||||||||||||||||||
| 948 | QAbstractNetworkCache *nc = managerPrivate->networkCache; | - | ||||||||||||||||||||||||
| 949 | if (nc) | - | ||||||||||||||||||||||||
| 950 | nc->remove(httpRequest.url()); | - | ||||||||||||||||||||||||
| 951 | } | - | ||||||||||||||||||||||||
| 952 | - | |||||||||||||||||||||||||
| 953 | void QNetworkReplyHttpImplPrivate::initCacheSaveDevice() | - | ||||||||||||||||||||||||
| 954 | { | - | ||||||||||||||||||||||||
| 955 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 956 | - | |||||||||||||||||||||||||
| 957 | // The disk cache does not support partial content, so don't even try to | - | ||||||||||||||||||||||||
| 958 | // save any such content into the cache. | - | ||||||||||||||||||||||||
| 959 | if (q->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 206) {
| 1-61 | ||||||||||||||||||||||||
| 960 | cacheEnabled = false; | - | ||||||||||||||||||||||||
| 961 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||||||||
| 962 | } | - | ||||||||||||||||||||||||
| 963 | - | |||||||||||||||||||||||||
| 964 | // save the meta data | - | ||||||||||||||||||||||||
| 965 | QNetworkCacheMetaData metaData; | - | ||||||||||||||||||||||||
| 966 | metaData.setUrl(url); | - | ||||||||||||||||||||||||
| 967 | metaData = fetchCacheMetaData(metaData); | - | ||||||||||||||||||||||||
| 968 | - | |||||||||||||||||||||||||
| 969 | // save the redirect request also in the cache | - | ||||||||||||||||||||||||
| 970 | QVariant redirectionTarget = q->attribute(QNetworkRequest::RedirectionTargetAttribute); | - | ||||||||||||||||||||||||
| 971 | if (redirectionTarget.isValid()) {
| 0-61 | ||||||||||||||||||||||||
| 972 | QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes(); | - | ||||||||||||||||||||||||
| 973 | attributes.insert(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget); | - | ||||||||||||||||||||||||
| 974 | metaData.setAttributes(attributes); | - | ||||||||||||||||||||||||
| 975 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 976 | - | |||||||||||||||||||||||||
| 977 | cacheSaveDevice = managerPrivate->networkCache->prepare(metaData); | - | ||||||||||||||||||||||||
| 978 | - | |||||||||||||||||||||||||
| 979 | if (cacheSaveDevice)
| 7-54 | ||||||||||||||||||||||||
| 980 | q->connect(cacheSaveDevice, SIGNAL(aboutToClose()), SLOT(_q_cacheSaveDeviceAboutToClose())); executed 54 times by 3 tests: q->connect(cacheSaveDevice, qFlagLocation("2""aboutToClose()" "\0" __FILE__ ":" "980"), qFlagLocation("1""_q_cacheSaveDeviceAboutToClose()" "\0" __FILE__ ":" "980"));Executed by:
| 54 | ||||||||||||||||||||||||
| 981 | - | |||||||||||||||||||||||||
| 982 | if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) {
| 0-54 | ||||||||||||||||||||||||
| 983 | if (Q_UNLIKELY(cacheSaveDevice && !cacheSaveDevice->isOpen())()))
| 0-7 | ||||||||||||||||||||||||
| 984 | qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- " never executed: QMessageLogger(__FILE__, 984, __PRETTY_FUNCTION__).critical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", managerPrivate->networkCache->metaObject()->className()); | 0 | ||||||||||||||||||||||||
| 985 | "class %s probably needs to be fixed", never executed: QMessageLogger(__FILE__, 984, __PRETTY_FUNCTION__).critical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", managerPrivate->networkCache->metaObject()->className()); | 0 | ||||||||||||||||||||||||
| 986 | managerPrivate->networkCache->metaObject()->className()); never executed: QMessageLogger(__FILE__, 984, __PRETTY_FUNCTION__).critical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", managerPrivate->networkCache->metaObject()->className()); | 0 | ||||||||||||||||||||||||
| 987 | - | |||||||||||||||||||||||||
| 988 | managerPrivate->networkCache->remove(url); | - | ||||||||||||||||||||||||
| 989 | cacheSaveDevice = 0; | - | ||||||||||||||||||||||||
| 990 | cacheEnabled = false; | - | ||||||||||||||||||||||||
| 991 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||||||||
| 992 | } executed 61 times by 3 tests: end of blockExecuted by:
| 61 | ||||||||||||||||||||||||
| 993 | - | |||||||||||||||||||||||||
| 994 | void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d) | - | ||||||||||||||||||||||||
| 995 | { | - | ||||||||||||||||||||||||
| 996 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 997 | - | |||||||||||||||||||||||||
| 998 | // If we're closed just ignore this data | - | ||||||||||||||||||||||||
| 999 | if (!q->isOpen())
| 1-6556 | ||||||||||||||||||||||||
| 1000 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||||||||
| 1001 | - | |||||||||||||||||||||||||
| 1002 | int pendingSignals = (int)pendingDownloadDataEmissions->fetchAndAddAcquire(-1) - 1; | - | ||||||||||||||||||||||||
| 1003 | - | |||||||||||||||||||||||||
| 1004 | if (pendingSignals > 0) {
| 1275-5281 | ||||||||||||||||||||||||
| 1005 | // Some more signal emissions to this slot are pending. | - | ||||||||||||||||||||||||
| 1006 | // Instead of writing the downstream data, we wait | - | ||||||||||||||||||||||||
| 1007 | // and do it in the next call we get | - | ||||||||||||||||||||||||
| 1008 | // (signal comppression) | - | ||||||||||||||||||||||||
| 1009 | pendingDownloadData.append(d); | - | ||||||||||||||||||||||||
| 1010 | return; executed 1275 times by 3 tests: return;Executed by:
| 1275 | ||||||||||||||||||||||||
| 1011 | } | - | ||||||||||||||||||||||||
| 1012 | - | |||||||||||||||||||||||||
| 1013 | pendingDownloadData.append(d); | - | ||||||||||||||||||||||||
| 1014 | d.clear(); | - | ||||||||||||||||||||||||
| 1015 | // We need to usa a copy for calling writeDownstreamData as we could | - | ||||||||||||||||||||||||
| 1016 | // possibly recurse into this this function when we call | - | ||||||||||||||||||||||||
| 1017 | // appendDownstreamDataSignalEmissions because the user might call | - | ||||||||||||||||||||||||
| 1018 | // processEvents() or spin an event loop when this occur. | - | ||||||||||||||||||||||||
| 1019 | QByteDataBuffer pendingDownloadDataCopy = pendingDownloadData; | - | ||||||||||||||||||||||||
| 1020 | pendingDownloadData.clear(); | - | ||||||||||||||||||||||||
| 1021 | - | |||||||||||||||||||||||||
| 1022 | if (cacheEnabled && isCachingAllowed() && !cacheSaveDevice) {
| 0-5236 | ||||||||||||||||||||||||
| 1023 | initCacheSaveDevice(); | - | ||||||||||||||||||||||||
| 1024 | } executed 45 times by 2 tests: end of blockExecuted by:
| 45 | ||||||||||||||||||||||||
| 1025 | - | |||||||||||||||||||||||||
| 1026 | qint64 bytesWritten = 0; | - | ||||||||||||||||||||||||
| 1027 | for (int i = 0; i < pendingDownloadDataCopy.bufferCount(); i++) {
| 5281-6554 | ||||||||||||||||||||||||
| 1028 | QByteArray const &item = pendingDownloadDataCopy[i]; | - | ||||||||||||||||||||||||
| 1029 | - | |||||||||||||||||||||||||
| 1030 | // This is going to look a little strange. When downloading data while a | - | ||||||||||||||||||||||||
| 1031 | // HTTP redirect is happening (and enabled), we write the redirect | - | ||||||||||||||||||||||||
| 1032 | // response to the cache. However, we do not append it to our internal | - | ||||||||||||||||||||||||
| 1033 | // buffer as that will contain the response data only for the final | - | ||||||||||||||||||||||||
| 1034 | // response | - | ||||||||||||||||||||||||
| 1035 | if (cacheSaveDevice)
| 44-6510 | ||||||||||||||||||||||||
| 1036 | cacheSaveDevice->write(item.constData(), item.size()); executed 44 times by 2 tests: cacheSaveDevice->write(item.constData(), item.size());Executed by:
| 44 | ||||||||||||||||||||||||
| 1037 | - | |||||||||||||||||||||||||
| 1038 | if (!isHttpRedirectResponse())
| 0-6554 | ||||||||||||||||||||||||
| 1039 | downloadMultiBufferbuffer.append(item); executed 6554 times by 4 tests: buffer.append(item);Executed by:
| 6554 | ||||||||||||||||||||||||
| 1040 | - | |||||||||||||||||||||||||
| 1041 | bytesWritten += item.size(); | - | ||||||||||||||||||||||||
| 1042 | } executed 6554 times by 4 tests: end of blockExecuted by:
| 6554 | ||||||||||||||||||||||||
| 1043 | bytesBuffered += bytesWritten; | - | ||||||||||||||||||||||||
| 1044 | pendingDownloadDataCopy.clear(); | - | ||||||||||||||||||||||||
| 1045 | - | |||||||||||||||||||||||||
| 1046 | QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); | - | ||||||||||||||||||||||||
| 1047 | if (preMigrationDownloaded != Q_INT64_C(-1))
| 0-5281 | ||||||||||||||||||||||||
| 1048 | totalSize = totalSize.toLongLong() + preMigrationDownloaded; never executed: totalSize = totalSize.toLongLong() + preMigrationDownloaded; | 0 | ||||||||||||||||||||||||
| 1049 | - | |||||||||||||||||||||||||
| 1050 | if (isHttpRedirectResponse())
| 0-5281 | ||||||||||||||||||||||||
| 1051 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1052 | - | |||||||||||||||||||||||||
| 1053 | bytesDownloaded += bytesWritten; | - | ||||||||||||||||||||||||
| 1054 | - | |||||||||||||||||||||||||
| 1055 | emit q->readyRead(); | - | ||||||||||||||||||||||||
| 1056 | // emit readyRead before downloadProgress incase this will cause events to be | - | ||||||||||||||||||||||||
| 1057 | // processed and we get into a recursive call (as in QProgressDialog). | - | ||||||||||||||||||||||||
| 1058 | if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
| 49-5232 | ||||||||||||||||||||||||
| 1059 | downloadProgressSignalChoke.restart(); | - | ||||||||||||||||||||||||
| 1060 | emit q->downloadProgress(bytesDownloaded, | - | ||||||||||||||||||||||||
| 1061 | totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong()); | - | ||||||||||||||||||||||||
| 1062 | } executed 49 times by 2 tests: end of blockExecuted by:
| 49 | ||||||||||||||||||||||||
| 1063 | - | |||||||||||||||||||||||||
| 1064 | } executed 5281 times by 4 tests: end of blockExecuted by:
| 5281 | ||||||||||||||||||||||||
| 1065 | - | |||||||||||||||||||||||||
| 1066 | void QNetworkReplyHttpImplPrivate::replyFinished() | - | ||||||||||||||||||||||||
| 1067 | { | - | ||||||||||||||||||||||||
| 1068 | // We are already loading from cache, we still however | - | ||||||||||||||||||||||||
| 1069 | // got this signal because it was posted already | - | ||||||||||||||||||||||||
| 1070 | if (loadingFromCache) | - | ||||||||||||||||||||||||
| 1071 | return; | - | ||||||||||||||||||||||||
| 1072 | - | |||||||||||||||||||||||||
| 1073 | finished(); | - | ||||||||||||||||||||||||
| 1074 | } | - | ||||||||||||||||||||||||
| 1075 | - | |||||||||||||||||||||||||
| 1076 | QNetworkAccessManager::Operation QNetworkReplyHttpImplPrivate::getRedirectOperation(QNetworkAccessManager::Operation currentOp, int httpStatus) | - | ||||||||||||||||||||||||
| 1077 | { | - | ||||||||||||||||||||||||
| 1078 | // HTTP status code can be used to decide if we can redirect with a GET | - | ||||||||||||||||||||||||
| 1079 | // operation or not. See http://www.ietf.org/rfc/rfc2616.txt [Sec 10.3] for | - | ||||||||||||||||||||||||
| 1080 | // more details | - | ||||||||||||||||||||||||
| 1081 | Q_UNUSED(httpStatus); | - | ||||||||||||||||||||||||
| 1082 | - | |||||||||||||||||||||||||
| 1083 | switch (currentOp) { | - | ||||||||||||||||||||||||
| 1084 | case QNetworkAccessManager::HeadOperation: | - | ||||||||||||||||||||||||
| 1085 | return QNetworkAccessManager::HeadOperation; | - | ||||||||||||||||||||||||
| 1086 | default: | - | ||||||||||||||||||||||||
| 1087 | break; | - | ||||||||||||||||||||||||
| 1088 | } | - | ||||||||||||||||||||||||
| 1089 | // For now, we're always returning GET for anything other than HEAD | - | ||||||||||||||||||||||||
| 1090 | return QNetworkAccessManager::GetOperation; | - | ||||||||||||||||||||||||
| 1091 | } | - | ||||||||||||||||||||||||
| 1092 | - | |||||||||||||||||||||||||
| 1093 | bool QNetworkReplyHttpImplPrivate::isHttpRedirectResponse() const | - | ||||||||||||||||||||||||
| 1094 | { | - | ||||||||||||||||||||||||
| 1095 | return httpRequest.isFollowRedirects() && QHttpNetworkReply::isHttpRedirect(statusCode); | - | ||||||||||||||||||||||||
| 1096 | } | - | ||||||||||||||||||||||||
| 1097 | - | |||||||||||||||||||||||||
| 1098 | QNetworkRequest QNetworkReplyHttpImplPrivate::createRedirectRequest(const QNetworkRequest &originalRequest, | - | ||||||||||||||||||||||||
| 1099 | const QUrl &url, | - | ||||||||||||||||||||||||
| 1100 | int maxRedirectsRemaining) | - | ||||||||||||||||||||||||
| 1101 | { | - | ||||||||||||||||||||||||
| 1102 | QNetworkRequest newRequest(originalRequest); | - | ||||||||||||||||||||||||
| 1103 | newRequest.setUrl(url); | - | ||||||||||||||||||||||||
| 1104 | newRequest.setMaximumRedirectsAllowed(maxRedirectsRemaining); | - | ||||||||||||||||||||||||
| 1105 | - | |||||||||||||||||||||||||
| 1106 | return newRequest; | - | ||||||||||||||||||||||||
| 1107 | } | - | ||||||||||||||||||||||||
| 1108 | - | |||||||||||||||||||||||||
| 1109 | void QNetworkReplyHttpImplPrivate::onRedirected(const QUrl &redirectUrl, int httpStatus, int maxRedirectsRemaining) | - | ||||||||||||||||||||||||
| 1110 | { | - | ||||||||||||||||||||||||
| 1111 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1112 | - | |||||||||||||||||||||||||
| 1113 | if (isFinished) | - | ||||||||||||||||||||||||
| 1114 | return; | - | ||||||||||||||||||||||||
| 1115 | - | |||||||||||||||||||||||||
| 1116 | if (httpRequest.isFollowRedirects()) // update the reply's url as it could've changed | - | ||||||||||||||||||||||||
| 1117 | url = redirectUrl; | - | ||||||||||||||||||||||||
| 1118 | - | |||||||||||||||||||||||||
| 1119 | QNetworkRequest redirectRequest = createRedirectRequest(originalRequest, redirectUrl, maxRedirectsRemaining); | - | ||||||||||||||||||||||||
| 1120 | operation = getRedirectOperation(operation, httpStatus); | - | ||||||||||||||||||||||||
| 1121 | - | |||||||||||||||||||||||||
| 1122 | cookedHeaders.clear(); | - | ||||||||||||||||||||||||
| 1123 | - | |||||||||||||||||||||||||
| 1124 | if (managerPrivate->httpThread) | - | ||||||||||||||||||||||||
| 1125 | managerPrivate->httpThread->disconnect(); | - | ||||||||||||||||||||||||
| 1126 | - | |||||||||||||||||||||||||
| 1127 | // Recurse | - | ||||||||||||||||||||||||
| 1128 | QMetaObject::invokeMethod(q, "start", Qt::QueuedConnection, | - | ||||||||||||||||||||||||
| 1129 | Q_ARG(QNetworkRequest, redirectRequest)); | - | ||||||||||||||||||||||||
| 1130 | - | |||||||||||||||||||||||||
| 1131 | emit q->redirected(redirectUrl); | - | ||||||||||||||||||||||||
| 1132 | } | - | ||||||||||||||||||||||||
| 1133 | - | |||||||||||||||||||||||||
| 1134 | void QNetworkReplyHttpImplPrivate::checkForRedirect(const int statusCode) | - | ||||||||||||||||||||||||
| 1135 | { | - | ||||||||||||||||||||||||
| 1136 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1137 | switch (statusCode) { | - | ||||||||||||||||||||||||
| 1138 | case 301: // Moved Permanently | - | ||||||||||||||||||||||||
| 1139 | case 302: // Found | - | ||||||||||||||||||||||||
| 1140 | case 303: // See Other | - | ||||||||||||||||||||||||
| 1141 | case 307: // Temporary Redirect | - | ||||||||||||||||||||||||
| 1142 | // What do we do about the caching of the HTML note? | - | ||||||||||||||||||||||||
| 1143 | // The response to a 303 MUST NOT be cached, while the response to | - | ||||||||||||||||||||||||
| 1144 | // all of the others is cacheable if the headers indicate it to be | - | ||||||||||||||||||||||||
| 1145 | QByteArray header = q->rawHeader("location"); | - | ||||||||||||||||||||||||
| 1146 | QUrl url = QUrl(QString::fromUtf8(header)); | - | ||||||||||||||||||||||||
| 1147 | if (!url.isValid()) | - | ||||||||||||||||||||||||
| 1148 | url = QUrl(QLatin1String(header)); | - | ||||||||||||||||||||||||
| 1149 | q->setAttribute(QNetworkRequest::RedirectionTargetAttribute, url); | - | ||||||||||||||||||||||||
| 1150 | } | - | ||||||||||||||||||||||||
| 1151 | } | - | ||||||||||||||||||||||||
| 1152 | - | |||||||||||||||||||||||||
| 1153 | void QNetworkReplyHttpImplPrivate::replyDownloadMetaData | - | ||||||||||||||||||||||||
| (const QList<QPair<QByteArray,QByteArray> > hm&hm, | ||||||||||||||||||||||||||
| 1154 | int sc, const QString rp&rp, bool pu, | - | ||||||||||||||||||||||||
| 1155 | QSharedPointer<char> db, | - | ||||||||||||||||||||||||
| 1156 | qint64 contentLength, bool spdyWasUsed) | - | ||||||||||||||||||||||||
| 1157 | { | - | ||||||||||||||||||||||||
| 1158 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1159 | Q_UNUSED(contentLength); | - | ||||||||||||||||||||||||
| 1160 | - | |||||||||||||||||||||||||
| 1161 | statusCode = sc; | - | ||||||||||||||||||||||||
| 1162 | reasonPhrase = rp; | - | ||||||||||||||||||||||||
| 1163 | - | |||||||||||||||||||||||||
| 1164 | // Download buffer | - | ||||||||||||||||||||||||
| 1165 | if (!db.isNull()) {
| 364-432 | ||||||||||||||||||||||||
| 1166 | downloadBufferPointer = db; | - | ||||||||||||||||||||||||
| 1167 | downloadZerocopyBuffer = downloadBufferPointer.data(); | - | ||||||||||||||||||||||||
| 1168 | downloadBufferCurrentSize = 0; | - | ||||||||||||||||||||||||
| 1169 | q->setAttribute(QNetworkRequest::DownloadBufferAttribute, QVariant::fromValue<QSharedPointer<char> > (downloadBufferPointer)); | - | ||||||||||||||||||||||||
| 1170 | } executed 364 times by 3 tests: end of blockExecuted by:
| 364 | ||||||||||||||||||||||||
| 1171 | - | |||||||||||||||||||||||||
| 1172 | q->setAttribute(QNetworkRequest::HttpPipeliningWasUsedAttribute, pu); | - | ||||||||||||||||||||||||
| 1173 | q->setAttribute(QNetworkRequest::SpdyWasUsedAttribute, spdyWasUsed); | - | ||||||||||||||||||||||||
| 1174 | - | |||||||||||||||||||||||||
| 1175 | // reconstruct the HTTP header | - | ||||||||||||||||||||||||
| 1176 | QList<QPair<QByteArray, QByteArray> > headerMap = hm; | - | ||||||||||||||||||||||||
| 1177 | QList<QPair<QByteArray, QByteArray> >::ConstIterator it = headerMap.constBegin(), | - | ||||||||||||||||||||||||
| 1178 | end = headerMap.constEnd(); | - | ||||||||||||||||||||||||
| 1179 | for (; it != end; ++it) {
| 796-5050 | ||||||||||||||||||||||||
| 1180 | QByteArray value = q->rawHeader(it->first); | - | ||||||||||||||||||||||||
| 1181 | - | |||||||||||||||||||||||||
| 1182 | // Reset any previous "location" header set in the reply. In case of | - | ||||||||||||||||||||||||
| 1183 | // redirects, we don't want to 'append' multiple location header values, | - | ||||||||||||||||||||||||
| 1184 | // rather we keep only the latest one | - | ||||||||||||||||||||||||
| 1185 | if (it->first.toLower() == "location")
| 43-5007 | ||||||||||||||||||||||||
| 1186 | value.clear(); executed 43 times by 2 tests: value.clear();Executed by:
| 43 | ||||||||||||||||||||||||
| 1187 | - | |||||||||||||||||||||||||
| 1188 | if (!value.isEmpty()) {
| 5-5045 | ||||||||||||||||||||||||
| 1189 | // Why are we appending values for headers which are already | - | ||||||||||||||||||||||||
| 1190 | // present? | - | ||||||||||||||||||||||||
| 1191 | if (qstricmp(it->first.constData(), "set-cookie") == 0)
| 2-3 | ||||||||||||||||||||||||
| 1192 | value += '\n'; executed 2 times by 1 test: value += '\n';Executed by:
| 2 | ||||||||||||||||||||||||
| 1193 | else | - | ||||||||||||||||||||||||
| 1194 | value += ", "; executed 3 times by 1 test: value += ", ";Executed by:
| 3 | ||||||||||||||||||||||||
| 1195 | } | - | ||||||||||||||||||||||||
| 1196 | value += it->second; | - | ||||||||||||||||||||||||
| 1197 | q->setRawHeader(it->first, value); | - | ||||||||||||||||||||||||
| 1198 | } executed 5050 times by 6 tests: end of blockExecuted by:
| 5050 | ||||||||||||||||||||||||
| 1199 | - | |||||||||||||||||||||||||
| 1200 | q->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, statusCode); | - | ||||||||||||||||||||||||
| 1201 | q->setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, reasonPhrase); | - | ||||||||||||||||||||||||
| 1202 | - | |||||||||||||||||||||||||
| 1203 | // is it a redirection? | - | ||||||||||||||||||||||||
| 1204 | if (!isHttpRedirectResponse())
| 6-790 | ||||||||||||||||||||||||
| 1205 | checkForRedirect(statusCode); executed 790 times by 6 tests: checkForRedirect(statusCode);Executed by:
| 790 | ||||||||||||||||||||||||
| 1206 | - | |||||||||||||||||||||||||
| 1207 | if (statusCode >= 500 && statusCode < 600) {
| 0-795 | ||||||||||||||||||||||||
| 1208 | QAbstractNetworkCache *nc = managerPrivate->networkCache; | - | ||||||||||||||||||||||||
| 1209 | if (nc) {
| 0-1 | ||||||||||||||||||||||||
| 1210 | QNetworkCacheMetaData metaData = nc->metaData(httpRequest.url()); | - | ||||||||||||||||||||||||
| 1211 | QNetworkHeadersPrivate cacheHeaders; | - | ||||||||||||||||||||||||
| 1212 | cacheHeaders.setAllRawHeaders(metaData.rawHeaders()); | - | ||||||||||||||||||||||||
| 1213 | QNetworkHeadersPrivate::RawHeadersList::ConstIterator it; | - | ||||||||||||||||||||||||
| 1214 | it = cacheHeaders.findRawHeader("Cache-Control"); | - | ||||||||||||||||||||||||
| 1215 | bool mustReValidate = false; | - | ||||||||||||||||||||||||
| 1216 | if (it != cacheHeaders.rawHeaders.constEnd()) {
| 0 | ||||||||||||||||||||||||
| 1217 | QHash<QByteArray, QByteArray> cacheControl = parseHttpOptionHeader(it->second); | - | ||||||||||||||||||||||||
| 1218 | if (cacheControl.contains("must-revalidate"))
| 0 | ||||||||||||||||||||||||
| 1219 | mustReValidate = true; never executed: mustReValidate = true; | 0 | ||||||||||||||||||||||||
| 1220 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1221 | if (!mustReValidate && sendCacheContents(metaData))
| 0 | ||||||||||||||||||||||||
| 1222 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1223 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1224 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 1225 | - | |||||||||||||||||||||||||
| 1226 | if (statusCode == 304) {
| 9-787 | ||||||||||||||||||||||||
| 1227 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||||||||
| 1228 | qDebug() << "Received a 304 from" << request.url(); | - | ||||||||||||||||||||||||
| 1229 | #endif | - | ||||||||||||||||||||||||
| 1230 | QAbstractNetworkCache *nc = managerPrivate->networkCache; | - | ||||||||||||||||||||||||
| 1231 | if (nc) {
| 0-9 | ||||||||||||||||||||||||
| 1232 | QNetworkCacheMetaData oldMetaData = nc->metaData(httpRequest.url()); | - | ||||||||||||||||||||||||
| 1233 | QNetworkCacheMetaData metaData = fetchCacheMetaData(oldMetaData); | - | ||||||||||||||||||||||||
| 1234 | if (oldMetaData != metaData)
| 0-9 | ||||||||||||||||||||||||
| 1235 | nc->updateMetaData(metaData); executed 9 times by 2 tests: nc->updateMetaData(metaData);Executed by:
| 9 | ||||||||||||||||||||||||
| 1236 | if (sendCacheContents(metaData))
| 0-9 | ||||||||||||||||||||||||
| 1237 | return; executed 9 times by 2 tests: return;Executed by:
| 9 | ||||||||||||||||||||||||
| 1238 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1239 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1240 | - | |||||||||||||||||||||||||
| 1241 | - | |||||||||||||||||||||||||
| 1242 | if (statusCode != 304 && statusCode != 303) {
| 0-787 | ||||||||||||||||||||||||
| 1243 | if (!isCachingEnabled())
| 0-787 | ||||||||||||||||||||||||
| 1244 | setCachingEnabled(true); executed 787 times by 6 tests: setCachingEnabled(true);Executed by:
| 787 | ||||||||||||||||||||||||
| 1245 | } executed 787 times by 6 tests: end of blockExecuted by:
| 787 | ||||||||||||||||||||||||
| 1246 | - | |||||||||||||||||||||||||
| 1247 | _q_metaDataChanged(); | - | ||||||||||||||||||||||||
| 1248 | } executed 787 times by 6 tests: end of blockExecuted by:
| 787 | ||||||||||||||||||||||||
| 1249 | - | |||||||||||||||||||||||||
| 1250 | void QNetworkReplyHttpImplPrivate::replyDownloadProgressSlot(qint64 bytesReceived, qint64 bytesTotal) | - | ||||||||||||||||||||||||
| 1251 | { | - | ||||||||||||||||||||||||
| 1252 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1253 | - | |||||||||||||||||||||||||
| 1254 | // If we're closed just ignore this data | - | ||||||||||||||||||||||||
| 1255 | if (!q->isOpen()) | - | ||||||||||||||||||||||||
| 1256 | return; | - | ||||||||||||||||||||||||
| 1257 | - | |||||||||||||||||||||||||
| 1258 | // we can be sure here that there is a download buffer | - | ||||||||||||||||||||||||
| 1259 | - | |||||||||||||||||||||||||
| 1260 | int pendingSignals = (int)pendingDownloadProgressEmissions->fetchAndAddAcquire(-1) - 1; | - | ||||||||||||||||||||||||
| 1261 | if (pendingSignals > 0) { | - | ||||||||||||||||||||||||
| 1262 | // Let's ignore this signal and look at the next one coming in | - | ||||||||||||||||||||||||
| 1263 | // (signal comppression) | - | ||||||||||||||||||||||||
| 1264 | return; | - | ||||||||||||||||||||||||
| 1265 | } | - | ||||||||||||||||||||||||
| 1266 | - | |||||||||||||||||||||||||
| 1267 | if (!q->isOpen()) | - | ||||||||||||||||||||||||
| 1268 | return; | - | ||||||||||||||||||||||||
| 1269 | - | |||||||||||||||||||||||||
| 1270 | if (cacheEnabled && isCachingAllowed() && bytesReceived == bytesTotal) { | - | ||||||||||||||||||||||||
| 1271 | // Write everything in one go if we use a download buffer. might be more performant. | - | ||||||||||||||||||||||||
| 1272 | initCacheSaveDevice(); | - | ||||||||||||||||||||||||
| 1273 | // need to check again if cache enabled and device exists | - | ||||||||||||||||||||||||
| 1274 | if (cacheSaveDevice && cacheEnabled) | - | ||||||||||||||||||||||||
| 1275 | cacheSaveDevice->write(downloadZerocopyBuffer, bytesTotal); | - | ||||||||||||||||||||||||
| 1276 | // FIXME where is it closed? | - | ||||||||||||||||||||||||
| 1277 | } | - | ||||||||||||||||||||||||
| 1278 | - | |||||||||||||||||||||||||
| 1279 | if (isHttpRedirectResponse()) | - | ||||||||||||||||||||||||
| 1280 | return; | - | ||||||||||||||||||||||||
| 1281 | - | |||||||||||||||||||||||||
| 1282 | bytesDownloaded = bytesReceived; | - | ||||||||||||||||||||||||
| 1283 | - | |||||||||||||||||||||||||
| 1284 | downloadBufferCurrentSize = bytesReceived; | - | ||||||||||||||||||||||||
| 1285 | - | |||||||||||||||||||||||||
| 1286 | // Only emit readyRead when actual data is there | - | ||||||||||||||||||||||||
| 1287 | // emit readyRead before downloadProgress incase this will cause events to be | - | ||||||||||||||||||||||||
| 1288 | // processed and we get into a recursive call (as in QProgressDialog). | - | ||||||||||||||||||||||||
| 1289 | if (bytesDownloaded > 0) | - | ||||||||||||||||||||||||
| 1290 | emit q->readyRead(); | - | ||||||||||||||||||||||||
| 1291 | if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) { | - | ||||||||||||||||||||||||
| 1292 | downloadProgressSignalChoke.restart(); | - | ||||||||||||||||||||||||
| 1293 | emit q->downloadProgress(bytesDownloaded, bytesTotal); | - | ||||||||||||||||||||||||
| 1294 | } | - | ||||||||||||||||||||||||
| 1295 | } | - | ||||||||||||||||||||||||
| 1296 | - | |||||||||||||||||||||||||
| 1297 | void QNetworkReplyHttpImplPrivate::httpAuthenticationRequired(const QHttpNetworkRequest &request, | - | ||||||||||||||||||||||||
| 1298 | QAuthenticator *auth) | - | ||||||||||||||||||||||||
| 1299 | { | - | ||||||||||||||||||||||||
| 1300 | managerPrivate->authenticationRequired(auth, q_func(), synchronous, url, &urlForLastAuthentication, request.withCredentials()); | - | ||||||||||||||||||||||||
| 1301 | } | - | ||||||||||||||||||||||||
| 1302 | - | |||||||||||||||||||||||||
| 1303 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||||||||
| 1304 | void QNetworkReplyHttpImplPrivate::proxyAuthenticationRequired(const QNetworkProxy &proxy, | - | ||||||||||||||||||||||||
| 1305 | QAuthenticator *authenticator) | - | ||||||||||||||||||||||||
| 1306 | { | - | ||||||||||||||||||||||||
| 1307 | managerPrivate->proxyAuthenticationRequired(request.url(), proxy, synchronous, authenticator, &lastProxyAuthentication); | - | ||||||||||||||||||||||||
| 1308 | } | - | ||||||||||||||||||||||||
| 1309 | #endif | - | ||||||||||||||||||||||||
| 1310 | - | |||||||||||||||||||||||||
| 1311 | void QNetworkReplyHttpImplPrivate::httpError(QNetworkReply::NetworkError errorCode, | - | ||||||||||||||||||||||||
| 1312 | const QString &errorString) | - | ||||||||||||||||||||||||
| 1313 | { | - | ||||||||||||||||||||||||
| 1314 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||||||||
| 1315 | qDebug() << "http error!" << errorCode << errorString; | - | ||||||||||||||||||||||||
| 1316 | #endif | - | ||||||||||||||||||||||||
| 1317 | - | |||||||||||||||||||||||||
| 1318 | // FIXME? | - | ||||||||||||||||||||||||
| 1319 | error(errorCode, errorString); | - | ||||||||||||||||||||||||
| 1320 | } | - | ||||||||||||||||||||||||
| 1321 | - | |||||||||||||||||||||||||
| 1322 | #ifndef QT_NO_SSL | - | ||||||||||||||||||||||||
| 1323 | void QNetworkReplyHttpImplPrivate::replyEncrypted() | - | ||||||||||||||||||||||||
| 1324 | { | - | ||||||||||||||||||||||||
| 1325 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1326 | emit q->encrypted(); | - | ||||||||||||||||||||||||
| 1327 | } | - | ||||||||||||||||||||||||
| 1328 | - | |||||||||||||||||||||||||
| 1329 | void QNetworkReplyHttpImplPrivate::replySslErrors( | - | ||||||||||||||||||||||||
| 1330 | const QList<QSslError> &list, bool *ignoreAll, QList<QSslError> *toBeIgnored) | - | ||||||||||||||||||||||||
| 1331 | { | - | ||||||||||||||||||||||||
| 1332 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1333 | emit q->sslErrors(list); | - | ||||||||||||||||||||||||
| 1334 | // Check if the callback set any ignore and return this here to http thread | - | ||||||||||||||||||||||||
| 1335 | if (pendingIgnoreAllSslErrors) | - | ||||||||||||||||||||||||
| 1336 | *ignoreAll = true; | - | ||||||||||||||||||||||||
| 1337 | if (!pendingIgnoreSslErrorsList.isEmpty()) | - | ||||||||||||||||||||||||
| 1338 | *toBeIgnored = pendingIgnoreSslErrorsList; | - | ||||||||||||||||||||||||
| 1339 | } | - | ||||||||||||||||||||||||
| 1340 | - | |||||||||||||||||||||||||
| 1341 | void QNetworkReplyHttpImplPrivate::replySslConfigurationChanged(const QSslConfiguration &sslConfiguration) | - | ||||||||||||||||||||||||
| 1342 | { | - | ||||||||||||||||||||||||
| 1343 | // Receiving the used SSL configuration from the HTTP thread | - | ||||||||||||||||||||||||
| 1344 | this->sslConfiguration = sslConfiguration; | - | ||||||||||||||||||||||||
| 1345 | } | - | ||||||||||||||||||||||||
| 1346 | - | |||||||||||||||||||||||||
| 1347 | void QNetworkReplyHttpImplPrivate::replyPreSharedKeyAuthenticationRequiredSlot(QSslPreSharedKeyAuthenticator *authenticator) | - | ||||||||||||||||||||||||
| 1348 | { | - | ||||||||||||||||||||||||
| 1349 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1350 | emit q->preSharedKeyAuthenticationRequired(authenticator); | - | ||||||||||||||||||||||||
| 1351 | } | - | ||||||||||||||||||||||||
| 1352 | #endif | - | ||||||||||||||||||||||||
| 1353 | - | |||||||||||||||||||||||||
| 1354 | // Coming from QNonContiguousByteDeviceThreadForwardImpl in HTTP thread | - | ||||||||||||||||||||||||
| 1355 | void QNetworkReplyHttpImplPrivate::resetUploadDataSlot(bool *r) | - | ||||||||||||||||||||||||
| 1356 | { | - | ||||||||||||||||||||||||
| 1357 | *r = uploadByteDevice->reset(); | - | ||||||||||||||||||||||||
| 1358 | if (*r) { | - | ||||||||||||||||||||||||
| 1359 | // reset our own position which is used for the inter-thread communication | - | ||||||||||||||||||||||||
| 1360 | uploadByteDevicePosition = 0; | - | ||||||||||||||||||||||||
| 1361 | } | - | ||||||||||||||||||||||||
| 1362 | } | - | ||||||||||||||||||||||||
| 1363 | - | |||||||||||||||||||||||||
| 1364 | // Coming from QNonContiguousByteDeviceThreadForwardImpl in HTTP thread | - | ||||||||||||||||||||||||
| 1365 | void QNetworkReplyHttpImplPrivate::sentUploadDataSlot(qint64 pos, qint64 amount) | - | ||||||||||||||||||||||||
| 1366 | { | - | ||||||||||||||||||||||||
| 1367 | if (uploadByteDevicePosition + amount != pos) { | - | ||||||||||||||||||||||||
| 1368 | // Sanity check, should not happen. | - | ||||||||||||||||||||||||
| 1369 | error(QNetworkReply::UnknownNetworkError, QString()); | - | ||||||||||||||||||||||||
| 1370 | return; | - | ||||||||||||||||||||||||
| 1371 | } | - | ||||||||||||||||||||||||
| 1372 | uploadByteDevice->advanceReadPointer(amount); | - | ||||||||||||||||||||||||
| 1373 | uploadByteDevicePosition += amount; | - | ||||||||||||||||||||||||
| 1374 | } | - | ||||||||||||||||||||||||
| 1375 | - | |||||||||||||||||||||||||
| 1376 | // Coming from QNonContiguousByteDeviceThreadForwardImpl in HTTP thread | - | ||||||||||||||||||||||||
| 1377 | void QNetworkReplyHttpImplPrivate::wantUploadDataSlot(qint64 maxSize) | - | ||||||||||||||||||||||||
| 1378 | { | - | ||||||||||||||||||||||||
| 1379 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1380 | - | |||||||||||||||||||||||||
| 1381 | // call readPointer | - | ||||||||||||||||||||||||
| 1382 | qint64 currentUploadDataLength = 0; | - | ||||||||||||||||||||||||
| 1383 | char *data = const_cast<char*>(uploadByteDevice->readPointer(maxSize, currentUploadDataLength)); | - | ||||||||||||||||||||||||
| 1384 | - | |||||||||||||||||||||||||
| 1385 | if (currentUploadDataLength == 0) { | - | ||||||||||||||||||||||||
| 1386 | uploadDeviceChoking = true; | - | ||||||||||||||||||||||||
| 1387 | // No bytes from upload byte device. There will be bytes later, it will emit readyRead() | - | ||||||||||||||||||||||||
| 1388 | // and our uploadByteDeviceReadyReadSlot() is called. | - | ||||||||||||||||||||||||
| 1389 | return; | - | ||||||||||||||||||||||||
| 1390 | } else { | - | ||||||||||||||||||||||||
| 1391 | uploadDeviceChoking = false; | - | ||||||||||||||||||||||||
| 1392 | } | - | ||||||||||||||||||||||||
| 1393 | - | |||||||||||||||||||||||||
| 1394 | // Let's make a copy of this data | - | ||||||||||||||||||||||||
| 1395 | QByteArray dataArray(data, currentUploadDataLength); | - | ||||||||||||||||||||||||
| 1396 | - | |||||||||||||||||||||||||
| 1397 | // Communicate back to HTTP thread | - | ||||||||||||||||||||||||
| 1398 | emit q->haveUploadData(uploadByteDevicePosition, dataArray, uploadByteDevice->atEnd(), uploadByteDevice->size()); | - | ||||||||||||||||||||||||
| 1399 | } | - | ||||||||||||||||||||||||
| 1400 | - | |||||||||||||||||||||||||
| 1401 | void QNetworkReplyHttpImplPrivate::uploadByteDeviceReadyReadSlot() | - | ||||||||||||||||||||||||
| 1402 | { | - | ||||||||||||||||||||||||
| 1403 | // Start the flow between this thread and the HTTP thread again by triggering a upload. | - | ||||||||||||||||||||||||
| 1404 | // However only do this when we were choking before, else the state in | - | ||||||||||||||||||||||||
| 1405 | // QNonContiguousByteDeviceThreadForwardImpl gets messed up. | - | ||||||||||||||||||||||||
| 1406 | if (uploadDeviceChoking) { | - | ||||||||||||||||||||||||
| 1407 | uploadDeviceChoking = false; | - | ||||||||||||||||||||||||
| 1408 | wantUploadDataSlot(1024); | - | ||||||||||||||||||||||||
| 1409 | } | - | ||||||||||||||||||||||||
| 1410 | } | - | ||||||||||||||||||||||||
| 1411 | - | |||||||||||||||||||||||||
| 1412 | - | |||||||||||||||||||||||||
| 1413 | /* | - | ||||||||||||||||||||||||
| 1414 | A simple web page that can be used to test us: http://www.procata.com/cachetest/ | - | ||||||||||||||||||||||||
| 1415 | */ | - | ||||||||||||||||||||||||
| 1416 | bool QNetworkReplyHttpImplPrivate::sendCacheContents(const QNetworkCacheMetaData &metaData) | - | ||||||||||||||||||||||||
| 1417 | { | - | ||||||||||||||||||||||||
| 1418 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1419 | - | |||||||||||||||||||||||||
| 1420 | setCachingEnabled(false); | - | ||||||||||||||||||||||||
| 1421 | if (!metaData.isValid()) | - | ||||||||||||||||||||||||
| 1422 | return false; | - | ||||||||||||||||||||||||
| 1423 | - | |||||||||||||||||||||||||
| 1424 | QAbstractNetworkCache *nc = managerPrivate->networkCache; | - | ||||||||||||||||||||||||
| 1425 | Q_ASSERT(nc); | - | ||||||||||||||||||||||||
| 1426 | QIODevice *contents = nc->data(url); | - | ||||||||||||||||||||||||
| 1427 | if (!contents) { | - | ||||||||||||||||||||||||
| 1428 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||||||||
| 1429 | qDebug() << "Can not send cache, the contents are 0" << url; | - | ||||||||||||||||||||||||
| 1430 | #endif | - | ||||||||||||||||||||||||
| 1431 | return false; | - | ||||||||||||||||||||||||
| 1432 | } | - | ||||||||||||||||||||||||
| 1433 | contents->setParent(q); | - | ||||||||||||||||||||||||
| 1434 | - | |||||||||||||||||||||||||
| 1435 | QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes(); | - | ||||||||||||||||||||||||
| 1436 | int status = attributes.value(QNetworkRequest::HttpStatusCodeAttribute).toInt(); | - | ||||||||||||||||||||||||
| 1437 | if (status < 100) | - | ||||||||||||||||||||||||
| 1438 | status = 200; // fake it | - | ||||||||||||||||||||||||
| 1439 | - | |||||||||||||||||||||||||
| 1440 | statusCode = status; | - | ||||||||||||||||||||||||
| 1441 | - | |||||||||||||||||||||||||
| 1442 | q->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, status); | - | ||||||||||||||||||||||||
| 1443 | q->setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, attributes.value(QNetworkRequest::HttpReasonPhraseAttribute)); | - | ||||||||||||||||||||||||
| 1444 | q->setAttribute(QNetworkRequest::SourceIsFromCacheAttribute, true); | - | ||||||||||||||||||||||||
| 1445 | - | |||||||||||||||||||||||||
| 1446 | QNetworkCacheMetaData::RawHeaderList rawHeaders = metaData.rawHeaders(); | - | ||||||||||||||||||||||||
| 1447 | QNetworkCacheMetaData::RawHeaderList::ConstIterator it = rawHeaders.constBegin(), | - | ||||||||||||||||||||||||
| 1448 | end = rawHeaders.constEnd(); | - | ||||||||||||||||||||||||
| 1449 | QUrl redirectUrl; | - | ||||||||||||||||||||||||
| 1450 | for ( ; it != end; ++it) { | - | ||||||||||||||||||||||||
| 1451 | if (httpRequest.isFollowRedirects() && | - | ||||||||||||||||||||||||
| 1452 | !qstricmp(it->first.toLower().constData(), "location")) | - | ||||||||||||||||||||||||
| 1453 | redirectUrl = QUrl::fromEncoded(it->second); | - | ||||||||||||||||||||||||
| 1454 | setRawHeader(it->first, it->second); | - | ||||||||||||||||||||||||
| 1455 | } | - | ||||||||||||||||||||||||
| 1456 | - | |||||||||||||||||||||||||
| 1457 | if (!isHttpRedirectResponse()) | - | ||||||||||||||||||||||||
| 1458 | checkForRedirect(status); | - | ||||||||||||||||||||||||
| 1459 | - | |||||||||||||||||||||||||
| 1460 | cacheLoadDevice = contents; | - | ||||||||||||||||||||||||
| 1461 | q->connect(cacheLoadDevice, SIGNAL(readyRead()), SLOT(_q_cacheLoadReadyRead())); | - | ||||||||||||||||||||||||
| 1462 | q->connect(cacheLoadDevice, SIGNAL(readChannelFinished()), SLOT(_q_cacheLoadReadyRead())); | - | ||||||||||||||||||||||||
| 1463 | - | |||||||||||||||||||||||||
| 1464 | // This needs to be emitted in the event loop because it can be reached at | - | ||||||||||||||||||||||||
| 1465 | // the direct code path of qnam.get(...) before the user has a chance | - | ||||||||||||||||||||||||
| 1466 | // to connect any signals. | - | ||||||||||||||||||||||||
| 1467 | QMetaObject::invokeMethod(q, "_q_metaDataChanged", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1468 | QMetaObject::invokeMethod(q, "_q_cacheLoadReadyRead", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1469 | - | |||||||||||||||||||||||||
| 1470 | - | |||||||||||||||||||||||||
| 1471 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||||||||
| 1472 | qDebug() << "Successfully sent cache:" << url << contents->size() << "bytes"; | - | ||||||||||||||||||||||||
| 1473 | #endif | - | ||||||||||||||||||||||||
| 1474 | - | |||||||||||||||||||||||||
| 1475 | // Do redirect processing | - | ||||||||||||||||||||||||
| 1476 | if (httpRequest.isFollowRedirects() && QHttpNetworkReply::isHttpRedirect(status)) { | - | ||||||||||||||||||||||||
| 1477 | QMetaObject::invokeMethod(q, "onRedirected", Qt::QueuedConnection, | - | ||||||||||||||||||||||||
| 1478 | Q_ARG(QUrl, redirectUrl), | - | ||||||||||||||||||||||||
| 1479 | Q_ARG(int, status), | - | ||||||||||||||||||||||||
| 1480 | Q_ARG(int, httpRequest.redirectCount() - 1)); | - | ||||||||||||||||||||||||
| 1481 | } | - | ||||||||||||||||||||||||
| 1482 | - | |||||||||||||||||||||||||
| 1483 | // Set the following flag so we can ignore some signals from HTTP thread | - | ||||||||||||||||||||||||
| 1484 | // that would still come | - | ||||||||||||||||||||||||
| 1485 | loadingFromCache = true; | - | ||||||||||||||||||||||||
| 1486 | return true; | - | ||||||||||||||||||||||||
| 1487 | } | - | ||||||||||||||||||||||||
| 1488 | - | |||||||||||||||||||||||||
| 1489 | QNetworkCacheMetaData QNetworkReplyHttpImplPrivate::fetchCacheMetaData(const QNetworkCacheMetaData &oldMetaData) const | - | ||||||||||||||||||||||||
| 1490 | { | - | ||||||||||||||||||||||||
| 1491 | Q_Q(const QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1492 | - | |||||||||||||||||||||||||
| 1493 | QNetworkCacheMetaData metaData = oldMetaData; | - | ||||||||||||||||||||||||
| 1494 | - | |||||||||||||||||||||||||
| 1495 | QNetworkHeadersPrivate cacheHeaders; | - | ||||||||||||||||||||||||
| 1496 | cacheHeaders.setAllRawHeaders(metaData.rawHeaders()); | - | ||||||||||||||||||||||||
| 1497 | QNetworkHeadersPrivate::RawHeadersList::ConstIterator it; | - | ||||||||||||||||||||||||
| 1498 | - | |||||||||||||||||||||||||
| 1499 | const QList<QByteArray> newHeaders = q->rawHeaderList(); | - | ||||||||||||||||||||||||
| 1500 | foreachfor (QByteArray header, : newHeaders) { | - | ||||||||||||||||||||||||
| 1501 | QByteArray originalHeader = header; | - | ||||||||||||||||||||||||
| 1502 | header = header.toLower(); | - | ||||||||||||||||||||||||
| 1503 | bool hop_by_hop = | - | ||||||||||||||||||||||||
| 1504 | (header == "connection"
| 69-387 | ||||||||||||||||||||||||
| 1505 | || header == "keep-alive"
| 62-325 | ||||||||||||||||||||||||
| 1506 | || header == "proxy-authenticate"
| 0-325 | ||||||||||||||||||||||||
| 1507 | || header == "proxy-authorization"
| 0-325 | ||||||||||||||||||||||||
| 1508 | || header == "te"
| 0-325 | ||||||||||||||||||||||||
| 1509 | || header == "trailers"
| 0-325 | ||||||||||||||||||||||||
| 1510 | || header == "transfer-encoding"
| 41-284 | ||||||||||||||||||||||||
| 1511 | || header == "upgrade");
| 0-284 | ||||||||||||||||||||||||
| 1512 | if (hop_by_hop)
| 172-284 | ||||||||||||||||||||||||
| 1513 | continue; executed 172 times by 2 tests: continue;Executed by:
| 172 | ||||||||||||||||||||||||
| 1514 | - | |||||||||||||||||||||||||
| 1515 | if (header == "set-cookie")
| 0-284 | ||||||||||||||||||||||||
| 1516 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 1517 | - | |||||||||||||||||||||||||
| 1518 | // for 4.6.0, we were planning to not store the date header in the | - | ||||||||||||||||||||||||
| 1519 | // cached resource; through that we planned to reduce the number | - | ||||||||||||||||||||||||
| 1520 | // of writes to disk when using a QNetworkDiskCache (i.e. don't | - | ||||||||||||||||||||||||
| 1521 | // write to disk when only the date changes). | - | ||||||||||||||||||||||||
| 1522 | // However, without the date we cannot calculate the age of the page | - | ||||||||||||||||||||||||
| 1523 | // anymore. | - | ||||||||||||||||||||||||
| 1524 | //if (header == "date") | - | ||||||||||||||||||||||||
| 1525 | //continue; | - | ||||||||||||||||||||||||
| 1526 | - | |||||||||||||||||||||||||
| 1527 | // Don't store Warning 1xx headers | - | ||||||||||||||||||||||||
| 1528 | if (header == "warning") {
| 0-284 | ||||||||||||||||||||||||
| 1529 | QByteArray v = q->rawHeader(header); | - | ||||||||||||||||||||||||
| 1530 | if (v.length() == 3
| 0 | ||||||||||||||||||||||||
| 1531 | && v[0] == '1'
| 0 | ||||||||||||||||||||||||
| 1532 | && v[1] >= '0' && v[1] <= '9'
| 0 | ||||||||||||||||||||||||
| 1533 | && v[2] >= '0' && v[2] <= '9')
| 0 | ||||||||||||||||||||||||
| 1534 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 1535 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1536 | - | |||||||||||||||||||||||||
| 1537 | it = cacheHeaders.findRawHeader(header); | - | ||||||||||||||||||||||||
| 1538 | if (it != cacheHeaders.rawHeaders.constEnd()) {
| 13-271 | ||||||||||||||||||||||||
| 1539 | // Match the behavior of Firefox and assume Cache-Control: "no-transform" | - | ||||||||||||||||||||||||
| 1540 | if (header == "content-encoding"
| 0-13 | ||||||||||||||||||||||||
| 1541 | || header == "content-range"
| 0-13 | ||||||||||||||||||||||||
| 1542 | || header == "content-type")
| 0-13 | ||||||||||||||||||||||||
| 1543 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 1544 | - | |||||||||||||||||||||||||
| 1545 | // For MS servers that send "Content-Length: 0" on 304 responses | - | ||||||||||||||||||||||||
| 1546 | // ignore this too | - | ||||||||||||||||||||||||
| 1547 | if (header == "content-length")
| 0-13 | ||||||||||||||||||||||||
| 1548 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 1549 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 1550 | - | |||||||||||||||||||||||||
| 1551 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||||||||
| 1552 | QByteArray n = q->rawHeader(header); | - | ||||||||||||||||||||||||
| 1553 | QByteArray o; | - | ||||||||||||||||||||||||
| 1554 | if (it != cacheHeaders.rawHeaders.constEnd()) | - | ||||||||||||||||||||||||
| 1555 | o = (*it).second; | - | ||||||||||||||||||||||||
| 1556 | if (n != o && header != "date") { | - | ||||||||||||||||||||||||
| 1557 | qDebug() << "replacing" << header; | - | ||||||||||||||||||||||||
| 1558 | qDebug() << "new" << n; | - | ||||||||||||||||||||||||
| 1559 | qDebug() << "old" << o; | - | ||||||||||||||||||||||||
| 1560 | } | - | ||||||||||||||||||||||||
| 1561 | #endif | - | ||||||||||||||||||||||||
| 1562 | cacheHeaders.setRawHeader(originalHeader, q->rawHeader(header)); | - | ||||||||||||||||||||||||
| 1563 | } executed 284 times by 3 tests: end of blockExecuted by:
| 284 | ||||||||||||||||||||||||
| 1564 | metaData.setRawHeaders(cacheHeaders.rawHeaders); | - | ||||||||||||||||||||||||
| 1565 | - | |||||||||||||||||||||||||
| 1566 | bool checkExpired = true; | - | ||||||||||||||||||||||||
| 1567 | - | |||||||||||||||||||||||||
| 1568 | QHash<QByteArray, QByteArray> cacheControl; | - | ||||||||||||||||||||||||
| 1569 | it = cacheHeaders.findRawHeader("Cache-Control"); | - | ||||||||||||||||||||||||
| 1570 | if (it != cacheHeaders.rawHeaders.constEnd()) {
| 28-42 | ||||||||||||||||||||||||
| 1571 | cacheControl = parseHttpOptionHeader(it->second); | - | ||||||||||||||||||||||||
| 1572 | QByteArray maxAge = cacheControl.value("max-age"); | - | ||||||||||||||||||||||||
| 1573 | if (!maxAge.isEmpty()) {
| 7-21 | ||||||||||||||||||||||||
| 1574 | checkExpired = false; | - | ||||||||||||||||||||||||
| 1575 | QDateTime dt = QDateTime::currentDateTimeUtc(); | - | ||||||||||||||||||||||||
| 1576 | dt = dt.addSecs(maxAge.toInt()); | - | ||||||||||||||||||||||||
| 1577 | metaData.setExpirationDate(dt); | - | ||||||||||||||||||||||||
| 1578 | } executed 21 times by 2 tests: end of blockExecuted by:
| 21 | ||||||||||||||||||||||||
| 1579 | } executed 28 times by 2 tests: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 1580 | if (checkExpired) {
| 21-49 | ||||||||||||||||||||||||
| 1581 | it = cacheHeaders.findRawHeader("expires"); | - | ||||||||||||||||||||||||
| 1582 | if (it != cacheHeaders.rawHeaders.constEnd()) {
| 17-32 | ||||||||||||||||||||||||
| 1583 | QDateTime expiredDateTime = QNetworkHeadersPrivate::fromHttpDate(it->second); | - | ||||||||||||||||||||||||
| 1584 | metaData.setExpirationDate(expiredDateTime); | - | ||||||||||||||||||||||||
| 1585 | } executed 17 times by 1 test: end of blockExecuted by:
| 17 | ||||||||||||||||||||||||
| 1586 | } executed 49 times by 2 tests: end of blockExecuted by:
| 49 | ||||||||||||||||||||||||
| 1587 | - | |||||||||||||||||||||||||
| 1588 | it = cacheHeaders.findRawHeader("last-modified"); | - | ||||||||||||||||||||||||
| 1589 | if (it != cacheHeaders.rawHeaders.constEnd())
| 29-41 | ||||||||||||||||||||||||
| 1590 | metaData.setLastModified(QNetworkHeadersPrivate::fromHttpDate(it->second)); executed 29 times by 1 test: metaData.setLastModified(QNetworkHeadersPrivate::fromHttpDate(it->second));Executed by:
| 29 | ||||||||||||||||||||||||
| 1591 | - | |||||||||||||||||||||||||
| 1592 | bool canDiskCache; | - | ||||||||||||||||||||||||
| 1593 | // only cache GET replies by default, all other replies (POST, PUT, DELETE) | - | ||||||||||||||||||||||||
| 1594 | // are not cacheable by default (according to RFC 2616 section 9) | - | ||||||||||||||||||||||||
| 1595 | if (httpRequest.operation() == QHttpNetworkRequest::Get) {
| 0-70 | ||||||||||||||||||||||||
| 1596 | - | |||||||||||||||||||||||||
| 1597 | canDiskCache = true; | - | ||||||||||||||||||||||||
| 1598 | // 14.32 | - | ||||||||||||||||||||||||
| 1599 | // HTTP/1.1 caches SHOULD treat "Pragma: no-cache" as if the client | - | ||||||||||||||||||||||||
| 1600 | // had sent "Cache-Control: no-cache". | - | ||||||||||||||||||||||||
| 1601 | it = cacheHeaders.findRawHeader("pragma"); | - | ||||||||||||||||||||||||
| 1602 | if (it != cacheHeaders.rawHeaders.constEnd()
| 0-70 | ||||||||||||||||||||||||
| 1603 | && it->second == "no-cache")
| 0 | ||||||||||||||||||||||||
| 1604 | canDiskCache = false; never executed: canDiskCache = false; | 0 | ||||||||||||||||||||||||
| 1605 | - | |||||||||||||||||||||||||
| 1606 | // HTTP/1.1. Check the Cache-Control header | - | ||||||||||||||||||||||||
| 1607 | if (cacheControl.contains("no-cache"))
| 7-63 | ||||||||||||||||||||||||
| 1608 | canDiskCache = false; executed 7 times by 1 test: canDiskCache = false;Executed by:
| 7 | ||||||||||||||||||||||||
| 1609 | else if (cacheControl.contains("no-store"))
| 0-63 | ||||||||||||||||||||||||
| 1610 | canDiskCache = false; never executed: canDiskCache = false; | 0 | ||||||||||||||||||||||||
| 1611 | - | |||||||||||||||||||||||||
| 1612 | // responses to POST might be cacheable | - | ||||||||||||||||||||||||
| 1613 | } else if (httpRequest.operation() == QHttpNetworkRequest::Post) { executed 70 times by 3 tests: end of blockExecuted by:
| 0-70 | ||||||||||||||||||||||||
| 1614 | - | |||||||||||||||||||||||||
| 1615 | canDiskCache = false; | - | ||||||||||||||||||||||||
| 1616 | // some pages contain "expires:" and "cache-control: no-cache" field, | - | ||||||||||||||||||||||||
| 1617 | // so we only might cache POST requests if we get "cache-control: max-age ..." | - | ||||||||||||||||||||||||
| 1618 | if (cacheControl.contains("max-age"))
| 0 | ||||||||||||||||||||||||
| 1619 | canDiskCache = true; never executed: canDiskCache = true; | 0 | ||||||||||||||||||||||||
| 1620 | - | |||||||||||||||||||||||||
| 1621 | // responses to PUT and DELETE are not cacheable | - | ||||||||||||||||||||||||
| 1622 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1623 | canDiskCache = false; | - | ||||||||||||||||||||||||
| 1624 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1625 | - | |||||||||||||||||||||||||
| 1626 | metaData.setSaveToDisk(canDiskCache); | - | ||||||||||||||||||||||||
| 1627 | QNetworkCacheMetaData::AttributesMap attributes; | - | ||||||||||||||||||||||||
| 1628 | if (statusCode != 304) {
| 9-61 | ||||||||||||||||||||||||
| 1629 | // update the status code | - | ||||||||||||||||||||||||
| 1630 | attributes.insert(QNetworkRequest::HttpStatusCodeAttribute, statusCode); | - | ||||||||||||||||||||||||
| 1631 | attributes.insert(QNetworkRequest::HttpReasonPhraseAttribute, reasonPhrase); | - | ||||||||||||||||||||||||
| 1632 | } else { executed 61 times by 3 tests: end of blockExecuted by:
| 61 | ||||||||||||||||||||||||
| 1633 | // this is a redirection, keep the attributes intact | - | ||||||||||||||||||||||||
| 1634 | attributes = oldMetaData.attributes(); | - | ||||||||||||||||||||||||
| 1635 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||
| 1636 | metaData.setAttributes(attributes); | - | ||||||||||||||||||||||||
| 1637 | return metaData; executed 70 times by 3 tests: return metaData;Executed by:
| 70 | ||||||||||||||||||||||||
| 1638 | } | - | ||||||||||||||||||||||||
| 1639 | - | |||||||||||||||||||||||||
| 1640 | bool QNetworkReplyHttpImplPrivate::canResume() const | - | ||||||||||||||||||||||||
| 1641 | { | - | ||||||||||||||||||||||||
| 1642 | Q_Q(const QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1643 | - | |||||||||||||||||||||||||
| 1644 | // Only GET operation supports resuming. | - | ||||||||||||||||||||||||
| 1645 | if (operation != QNetworkAccessManager::GetOperation) | - | ||||||||||||||||||||||||
| 1646 | return false; | - | ||||||||||||||||||||||||
| 1647 | - | |||||||||||||||||||||||||
| 1648 | // Can only resume if server/resource supports Range header. | - | ||||||||||||||||||||||||
| 1649 | QByteArray acceptRangesheaderName("Accept-Ranges"); | - | ||||||||||||||||||||||||
| 1650 | if (!q->hasRawHeader(acceptRangesheaderName) || q->rawHeader(acceptRangesheaderName) == "none") | - | ||||||||||||||||||||||||
| 1651 | return false; | - | ||||||||||||||||||||||||
| 1652 | - | |||||||||||||||||||||||||
| 1653 | // We only support resuming for byte ranges. | - | ||||||||||||||||||||||||
| 1654 | if (request.hasRawHeader("Range")) { | - | ||||||||||||||||||||||||
| 1655 | QByteArray range = request.rawHeader("Range"); | - | ||||||||||||||||||||||||
| 1656 | if (!range.startsWith("bytes=")) | - | ||||||||||||||||||||||||
| 1657 | return false; | - | ||||||||||||||||||||||||
| 1658 | } | - | ||||||||||||||||||||||||
| 1659 | - | |||||||||||||||||||||||||
| 1660 | // If we're using a download buffer then we don't support resuming/migration | - | ||||||||||||||||||||||||
| 1661 | // right now. Too much trouble. | - | ||||||||||||||||||||||||
| 1662 | if (downloadZerocopyBuffer) | - | ||||||||||||||||||||||||
| 1663 | return false; | - | ||||||||||||||||||||||||
| 1664 | - | |||||||||||||||||||||||||
| 1665 | return true; | - | ||||||||||||||||||||||||
| 1666 | } | - | ||||||||||||||||||||||||
| 1667 | - | |||||||||||||||||||||||||
| 1668 | void QNetworkReplyHttpImplPrivate::setResumeOffset(quint64 offset) | - | ||||||||||||||||||||||||
| 1669 | { | - | ||||||||||||||||||||||||
| 1670 | resumeOffset = offset; | - | ||||||||||||||||||||||||
| 1671 | } | - | ||||||||||||||||||||||||
| 1672 | - | |||||||||||||||||||||||||
| 1673 | /*! | - | ||||||||||||||||||||||||
| 1674 | Starts the backend. Returns \c true if the backend is started. Returns \c false if the backend | - | ||||||||||||||||||||||||
| 1675 | could not be started due to an unopened or roaming session. The caller should recall this | - | ||||||||||||||||||||||||
| 1676 | function once the session has been opened or the roaming process has finished. | - | ||||||||||||||||||||||||
| 1677 | */ | - | ||||||||||||||||||||||||
| 1678 | bool QNetworkReplyHttpImplPrivate::start(const QNetworkRequest &newHttpRequest) | - | ||||||||||||||||||||||||
| 1679 | { | - | ||||||||||||||||||||||||
| 1680 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||||||||
| 1681 | QSharedPointer<QNetworkSession> networkSession(managerPrivate->getNetworkSession()); | - | ||||||||||||||||||||||||
| 1682 | if (!networkSession) { | - | ||||||||||||||||||||||||
| 1683 | #endif | - | ||||||||||||||||||||||||
| 1684 | postRequest(newHttpRequest); | - | ||||||||||||||||||||||||
| 1685 | return true; | - | ||||||||||||||||||||||||
| 1686 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||||||||
| 1687 | } | - | ||||||||||||||||||||||||
| 1688 | - | |||||||||||||||||||||||||
| 1689 | // This is not ideal. | - | ||||||||||||||||||||||||
| 1690 | const QString host = url.host(); | - | ||||||||||||||||||||||||
| 1691 | if (host == QLatin1String("localhost") || | - | ||||||||||||||||||||||||
| 1692 | QHostAddress(host).isLoopback()) { | - | ||||||||||||||||||||||||
| 1693 | // Don't need an open session for localhost access. | - | ||||||||||||||||||||||||
| 1694 | postRequest(newHttpRequest); | - | ||||||||||||||||||||||||
| 1695 | return true; | - | ||||||||||||||||||||||||
| 1696 | } | - | ||||||||||||||||||||||||
| 1697 | - | |||||||||||||||||||||||||
| 1698 | if (networkSession->isOpen() && | - | ||||||||||||||||||||||||
| 1699 | networkSession->state() == QNetworkSession::Connected) { | - | ||||||||||||||||||||||||
| 1700 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1701 | QObject::connect(networkSession.data(), SIGNAL(usagePoliciesChanged(QNetworkSession::UsagePolicies)), | - | ||||||||||||||||||||||||
| 1702 | q, SLOT(_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies))); | - | ||||||||||||||||||||||||
| 1703 | postRequest(newHttpRequest); | - | ||||||||||||||||||||||||
| 1704 | return true; | - | ||||||||||||||||||||||||
| 1705 | } else if (synchronous) { | - | ||||||||||||||||||||||||
| 1706 | // Command line applications using the synchronous path such as xmlpatterns may need an extra push. | - | ||||||||||||||||||||||||
| 1707 | networkSession->open(); | - | ||||||||||||||||||||||||
| 1708 | if (networkSession->waitForOpened()) { | - | ||||||||||||||||||||||||
| 1709 | postRequest(newHttpRequest); | - | ||||||||||||||||||||||||
| 1710 | return true; | - | ||||||||||||||||||||||||
| 1711 | } | - | ||||||||||||||||||||||||
| 1712 | } | - | ||||||||||||||||||||||||
| 1713 | return false; | - | ||||||||||||||||||||||||
| 1714 | #endif | - | ||||||||||||||||||||||||
| 1715 | } | - | ||||||||||||||||||||||||
| 1716 | - | |||||||||||||||||||||||||
| 1717 | void QNetworkReplyHttpImplPrivate::_q_startOperation() | - | ||||||||||||||||||||||||
| 1718 | { | - | ||||||||||||||||||||||||
| 1719 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1720 | - | |||||||||||||||||||||||||
| 1721 | // ensure this function is only being called once | - | ||||||||||||||||||||||||
| 1722 | if (state == Working) {
| 0-943 | ||||||||||||||||||||||||
| 1723 | qDebug("QNetworkReplyImpl() << "QNetworkReplyHttpImplPrivate::_q_startOperation was called more than once"); << url; | - | ||||||||||||||||||||||||
| 1724 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1725 | } | - | ||||||||||||||||||||||||
| 1726 | state = Working; | - | ||||||||||||||||||||||||
| 1727 | - | |||||||||||||||||||||||||
| 1728 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||||||||
| 1729 | // Do not start background requests if they are not allowed by session policy | - | ||||||||||||||||||||||||
| 1730 | QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession()); | - | ||||||||||||||||||||||||
| 1731 | QVariant isBackground = request.attribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(false)); | - | ||||||||||||||||||||||||
| 1732 | if (isBackground.toBool() && session && session->usagePolicies().testFlag(QNetworkSession::NoBackgroundTrafficPolicy)) {
| 0-935 | ||||||||||||||||||||||||
| 1733 | QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, | - | ||||||||||||||||||||||||
| 1734 | Q_ARG(QNetworkReply::NetworkError, QNetworkReply::BackgroundRequestNotAllowedError), | - | ||||||||||||||||||||||||
| 1735 | Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "Background request not allowed."))); | - | ||||||||||||||||||||||||
| 1736 | QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1737 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 1738 | } | - | ||||||||||||||||||||||||
| 1739 | - | |||||||||||||||||||||||||
| 1740 | if (!start(request)) {
| 56-885 | ||||||||||||||||||||||||
| 1741 | // backend failed to start because the session state is not Connected. | - | ||||||||||||||||||||||||
| 1742 | // QNetworkAccessManager will call reply->backend->start() again for us when the session | - | ||||||||||||||||||||||||
| 1743 | // state changes. | - | ||||||||||||||||||||||||
| 1744 | state = WaitingForSession; | - | ||||||||||||||||||||||||
| 1745 | - | |||||||||||||||||||||||||
| 1746 | if (session) {
| 0-56 | ||||||||||||||||||||||||
| 1747 | QObject::connect(session.data(), SIGNAL(error(QNetworkSession::SessionError)), | - | ||||||||||||||||||||||||
| 1748 | q, SLOT(_q_networkSessionFailed()), Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1749 | - | |||||||||||||||||||||||||
| 1750 | if (!session->isOpen()) {
| 0-56 | ||||||||||||||||||||||||
| 1751 | session->setSessionProperty(QStringLiteral("ConnectInBackground"), isBackground); | - | ||||||||||||||||||||||||
| 1752 | session->open(); | - | ||||||||||||||||||||||||
| 1753 | } executed 56 times by 5 tests: end of blockExecuted by:
| 56 | ||||||||||||||||||||||||
| 1754 | } else { executed 56 times by 5 tests: end of blockExecuted by:
| 56 | ||||||||||||||||||||||||
| 1755 | qWarning("Backend is waiting for QNetworkSession to connect, but there is none!"); | - | ||||||||||||||||||||||||
| 1756 | QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, | - | ||||||||||||||||||||||||
| 1757 | Q_ARG(QNetworkReply::NetworkError, QNetworkReply::NetworkSessionFailedError), | - | ||||||||||||||||||||||||
| 1758 | Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "Network session error."))); | - | ||||||||||||||||||||||||
| 1759 | QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1760 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1761 | } | - | ||||||||||||||||||||||||
| 1762 | } else if (session) {
| 0-885 | ||||||||||||||||||||||||
| 1763 | QObject::connect(session.data(), SIGNAL(stateChanged(QNetworkSession::State)), | - | ||||||||||||||||||||||||
| 1764 | q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)), | - | ||||||||||||||||||||||||
| 1765 | Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1766 | } executed 885 times by 8 tests: end of blockExecuted by:
| 885 | ||||||||||||||||||||||||
| 1767 | #else | - | ||||||||||||||||||||||||
| 1768 | if (!start(request)) { | - | ||||||||||||||||||||||||
| 1769 | qWarning("Backend start failed"); | - | ||||||||||||||||||||||||
| 1770 | QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, | - | ||||||||||||||||||||||||
| 1771 | Q_ARG(QNetworkReply::NetworkError, QNetworkReply::UnknownNetworkError), | - | ||||||||||||||||||||||||
| 1772 | Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "backend start error."))); | - | ||||||||||||||||||||||||
| 1773 | QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1774 | return; | - | ||||||||||||||||||||||||
| 1775 | } | - | ||||||||||||||||||||||||
| 1776 | #endif // QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||||||||
| 1777 | - | |||||||||||||||||||||||||
| 1778 | if (synchronous) {
| 76-865 | ||||||||||||||||||||||||
| 1779 | state = Finished; | - | ||||||||||||||||||||||||
| 1780 | q_func()->setFinished(true); | - | ||||||||||||||||||||||||
| 1781 | } executed 76 times by 1 test: end of blockExecuted by:
| 76 | ||||||||||||||||||||||||
| 1782 | } executed 941 times by 8 tests: end of blockExecuted by:
| 941 | ||||||||||||||||||||||||
| 1783 | - | |||||||||||||||||||||||||
| 1784 | void QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead() | - | ||||||||||||||||||||||||
| 1785 | { | - | ||||||||||||||||||||||||
| 1786 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1787 | - | |||||||||||||||||||||||||
| 1788 | if (state != Working)
| 0-27 | ||||||||||||||||||||||||
| 1789 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1790 | if (!cacheLoadDevice || !q->isOpen() || !cacheLoadDevice->bytesAvailable())
| 0-27 | ||||||||||||||||||||||||
| 1791 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1792 | - | |||||||||||||||||||||||||
| 1793 | // FIXME Optimize to use zerocopy download buffer if it is a QBuffer. | - | ||||||||||||||||||||||||
| 1794 | // Needs to be done where sendCacheContents() (?) of HTTP is emitting | - | ||||||||||||||||||||||||
| 1795 | // metaDataChanged ? | - | ||||||||||||||||||||||||
| 1796 | - | |||||||||||||||||||||||||
| 1797 | - | |||||||||||||||||||||||||
| 1798 | QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); | - | ||||||||||||||||||||||||
| 1799 | - | |||||||||||||||||||||||||
| 1800 | // emit readyRead before downloadProgress incase this will cause events to be | - | ||||||||||||||||||||||||
| 1801 | // processed and we get into a recursive call (as in QProgressDialog). | - | ||||||||||||||||||||||||
| 1802 | - | |||||||||||||||||||||||||
| 1803 | if (!(isHttpRedirectResponse())) {
| 0-27 | ||||||||||||||||||||||||
| 1804 | // This readyRead() goes to the user. The user then may or may not read() anything. | - | ||||||||||||||||||||||||
| 1805 | emit q->readyRead(); | - | ||||||||||||||||||||||||
| 1806 | - | |||||||||||||||||||||||||
| 1807 | if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
| 0-27 | ||||||||||||||||||||||||
| 1808 | downloadProgressSignalChoke.restart(); | - | ||||||||||||||||||||||||
| 1809 | emit q->downloadProgress(bytesDownloaded, | - | ||||||||||||||||||||||||
| 1810 | totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong()); | - | ||||||||||||||||||||||||
| 1811 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1812 | } executed 27 times by 2 tests: end of blockExecuted by:
| 27 | ||||||||||||||||||||||||
| 1813 | // If there are still bytes available in the cacheLoadDevice then the user did not read | - | ||||||||||||||||||||||||
| 1814 | // in response to the readyRead() signal. This means we have to load from the cacheLoadDevice | - | ||||||||||||||||||||||||
| 1815 | // and buffer that stuff. This is needed to be able to properly emit finished() later. | - | ||||||||||||||||||||||||
| 1816 | while (cacheLoadDevice->bytesAvailable() && !isHttpRedirectResponse()) {
| 0-27 | ||||||||||||||||||||||||
| 1817 | downloadMultiBufferbuffer.append(cacheLoadDevice->readAll()); executed 27 times by 2 tests: buffer.append(cacheLoadDevice->readAll());Executed by:
| 27 | ||||||||||||||||||||||||
| } executed 27 times by 2 tests: buffer.append(cacheLoadDevice->readAll());Executed by:
| ||||||||||||||||||||||||||
| 1818 | - | |||||||||||||||||||||||||
| 1819 | if (cacheLoadDevice->isSequential()) {
| 0-27 | ||||||||||||||||||||||||
| 1820 | // check if end and we can read the EOF -1 | - | ||||||||||||||||||||||||
| 1821 | char c; | - | ||||||||||||||||||||||||
| 1822 | qint64 actualCount = cacheLoadDevice->read(&c, 1); | - | ||||||||||||||||||||||||
| 1823 | if (actualCount < 0) {
| 0 | ||||||||||||||||||||||||
| 1824 | cacheLoadDevice->deleteLater(); | - | ||||||||||||||||||||||||
| 1825 | cacheLoadDevice = 0; | - | ||||||||||||||||||||||||
| 1826 | QMetaObject::invokeMethod(q, "_q_finished", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1827 | } else if (actualCount == 1) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1828 | // This is most probably not happening since most QIODevice returned something proper for bytesAvailable() | - | ||||||||||||||||||||||||
| 1829 | // and had already been "emptied". | - | ||||||||||||||||||||||||
| 1830 | cacheLoadDevice->ungetChar(c); | - | ||||||||||||||||||||||||
| 1831 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1832 | } else if ((!cacheLoadDevice->isSequential() && cacheLoadDevice->atEnd())) { never executed: end of block
| 0-27 | ||||||||||||||||||||||||
| 1833 | // This codepath is in case the cache device is a QBuffer, e.g. from QNetworkDiskCache. | - | ||||||||||||||||||||||||
| 1834 | cacheLoadDevice->deleteLater(); | - | ||||||||||||||||||||||||
| 1835 | cacheLoadDevice = 0; | - | ||||||||||||||||||||||||
| 1836 | QMetaObject::invokeMethod(q, "_q_finished", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1837 | } executed 27 times by 2 tests: end of blockExecuted by:
| 27 | ||||||||||||||||||||||||
| 1838 | } executed 27 times by 2 tests: end of blockExecuted by:
| 27 | ||||||||||||||||||||||||
| 1839 | - | |||||||||||||||||||||||||
| 1840 | - | |||||||||||||||||||||||||
| 1841 | void QNetworkReplyHttpImplPrivate::_q_bufferOutgoingDataFinished() | - | ||||||||||||||||||||||||
| 1842 | { | - | ||||||||||||||||||||||||
| 1843 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1844 | - | |||||||||||||||||||||||||
| 1845 | // make sure this is only called once, ever. | - | ||||||||||||||||||||||||
| 1846 | //_q_bufferOutgoingData may call it or the readChannelFinished emission | - | ||||||||||||||||||||||||
| 1847 | if (state != Buffering) | - | ||||||||||||||||||||||||
| 1848 | return; | - | ||||||||||||||||||||||||
| 1849 | - | |||||||||||||||||||||||||
| 1850 | // disconnect signals | - | ||||||||||||||||||||||||
| 1851 | QObject::disconnect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData())); | - | ||||||||||||||||||||||||
| 1852 | QObject::disconnect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished())); | - | ||||||||||||||||||||||||
| 1853 | - | |||||||||||||||||||||||||
| 1854 | // finally, start the request | - | ||||||||||||||||||||||||
| 1855 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1856 | } | - | ||||||||||||||||||||||||
| 1857 | - | |||||||||||||||||||||||||
| 1858 | void QNetworkReplyHttpImplPrivate::_q_cacheSaveDeviceAboutToClose() | - | ||||||||||||||||||||||||
| 1859 | { | - | ||||||||||||||||||||||||
| 1860 | // do not keep a dangling pointer to the device around (device | - | ||||||||||||||||||||||||
| 1861 | // is closing because e.g. QAbstractNetworkCache::remove() was called). | - | ||||||||||||||||||||||||
| 1862 | cacheSaveDevice = 0; | - | ||||||||||||||||||||||||
| 1863 | } | - | ||||||||||||||||||||||||
| 1864 | - | |||||||||||||||||||||||||
| 1865 | void QNetworkReplyHttpImplPrivate::_q_bufferOutgoingData() | - | ||||||||||||||||||||||||
| 1866 | { | - | ||||||||||||||||||||||||
| 1867 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1868 | - | |||||||||||||||||||||||||
| 1869 | if (!outgoingDataBuffer) { | - | ||||||||||||||||||||||||
| 1870 | // first call, create our buffer | - | ||||||||||||||||||||||||
| 1871 | outgoingDataBuffer = QSharedPointer<QRingBuffer>::create(); | - | ||||||||||||||||||||||||
| 1872 | - | |||||||||||||||||||||||||
| 1873 | QObject::connect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData())); | - | ||||||||||||||||||||||||
| 1874 | QObject::connect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished())); | - | ||||||||||||||||||||||||
| 1875 | } | - | ||||||||||||||||||||||||
| 1876 | - | |||||||||||||||||||||||||
| 1877 | qint64 bytesBuffered = 0; | - | ||||||||||||||||||||||||
| 1878 | qint64 bytesToBuffer = 0; | - | ||||||||||||||||||||||||
| 1879 | - | |||||||||||||||||||||||||
| 1880 | // read data into our buffer | - | ||||||||||||||||||||||||
| 1881 | forever { | - | ||||||||||||||||||||||||
| 1882 | bytesToBuffer = outgoingData->bytesAvailable(); | - | ||||||||||||||||||||||||
| 1883 | // unknown? just try 2 kB, this also ensures we always try to read the EOF | - | ||||||||||||||||||||||||
| 1884 | if (bytesToBuffer <= 0) | - | ||||||||||||||||||||||||
| 1885 | bytesToBuffer = 2*1024; | - | ||||||||||||||||||||||||
| 1886 | - | |||||||||||||||||||||||||
| 1887 | char *dst = outgoingDataBuffer->reserve(bytesToBuffer); | - | ||||||||||||||||||||||||
| 1888 | bytesBuffered = outgoingData->read(dst, bytesToBuffer); | - | ||||||||||||||||||||||||
| 1889 | - | |||||||||||||||||||||||||
| 1890 | if (bytesBuffered == -1) { | - | ||||||||||||||||||||||||
| 1891 | // EOF has been reached. | - | ||||||||||||||||||||||||
| 1892 | outgoingDataBuffer->chop(bytesToBuffer); | - | ||||||||||||||||||||||||
| 1893 | - | |||||||||||||||||||||||||
| 1894 | _q_bufferOutgoingDataFinished(); | - | ||||||||||||||||||||||||
| 1895 | break; | - | ||||||||||||||||||||||||
| 1896 | } else if (bytesBuffered == 0) { | - | ||||||||||||||||||||||||
| 1897 | // nothing read right now, just wait until we get called again | - | ||||||||||||||||||||||||
| 1898 | outgoingDataBuffer->chop(bytesToBuffer); | - | ||||||||||||||||||||||||
| 1899 | - | |||||||||||||||||||||||||
| 1900 | break; | - | ||||||||||||||||||||||||
| 1901 | } else { | - | ||||||||||||||||||||||||
| 1902 | // don't break, try to read() again | - | ||||||||||||||||||||||||
| 1903 | outgoingDataBuffer->chop(bytesToBuffer - bytesBuffered); | - | ||||||||||||||||||||||||
| 1904 | } | - | ||||||||||||||||||||||||
| 1905 | } | - | ||||||||||||||||||||||||
| 1906 | } | - | ||||||||||||||||||||||||
| 1907 | - | |||||||||||||||||||||||||
| 1908 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||||||||
| 1909 | void QNetworkReplyHttpImplPrivate::_q_networkSessionConnected() | - | ||||||||||||||||||||||||
| 1910 | { | - | ||||||||||||||||||||||||
| 1911 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1912 | - | |||||||||||||||||||||||||
| 1913 | if (!manager) | - | ||||||||||||||||||||||||
| 1914 | return; | - | ||||||||||||||||||||||||
| 1915 | - | |||||||||||||||||||||||||
| 1916 | QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession(); | - | ||||||||||||||||||||||||
| 1917 | if (!session) | - | ||||||||||||||||||||||||
| 1918 | return; | - | ||||||||||||||||||||||||
| 1919 | - | |||||||||||||||||||||||||
| 1920 | if (session->state() != QNetworkSession::Connected) | - | ||||||||||||||||||||||||
| 1921 | return; | - | ||||||||||||||||||||||||
| 1922 | - | |||||||||||||||||||||||||
| 1923 | switch (state) { | - | ||||||||||||||||||||||||
| 1924 | case QNetworkReplyPrivate::Buffering: | - | ||||||||||||||||||||||||
| 1925 | case QNetworkReplyPrivate::Working: | - | ||||||||||||||||||||||||
| 1926 | case QNetworkReplyPrivate::Reconnecting: | - | ||||||||||||||||||||||||
| 1927 | // Migrate existing downloads to new network connection. | - | ||||||||||||||||||||||||
| 1928 | migrateBackend(); | - | ||||||||||||||||||||||||
| 1929 | break; | - | ||||||||||||||||||||||||
| 1930 | case QNetworkReplyPrivate::WaitingForSession: | - | ||||||||||||||||||||||||
| 1931 | // Start waiting requests. | - | ||||||||||||||||||||||||
| 1932 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1933 | break; | - | ||||||||||||||||||||||||
| 1934 | default: | - | ||||||||||||||||||||||||
| 1935 | ; | - | ||||||||||||||||||||||||
| 1936 | } | - | ||||||||||||||||||||||||
| 1937 | } | - | ||||||||||||||||||||||||
| 1938 | - | |||||||||||||||||||||||||
| 1939 | void QNetworkReplyHttpImplPrivate::_q_networkSessionStateChanged(QNetworkSession::State sessionState) | - | ||||||||||||||||||||||||
| 1940 | { | - | ||||||||||||||||||||||||
| 1941 | if (sessionState == QNetworkSession::Disconnected | - | ||||||||||||||||||||||||
| 1942 | && state != Idle && state != Reconnecting) { | - | ||||||||||||||||||||||||
| 1943 | error(QNetworkReplyImpl::NetworkSessionFailedError, | - | ||||||||||||||||||||||||
| 1944 | QCoreApplication::translate("QNetworkReply", "Network session error.")); | - | ||||||||||||||||||||||||
| 1945 | finished(); | - | ||||||||||||||||||||||||
| 1946 | } | - | ||||||||||||||||||||||||
| 1947 | } | - | ||||||||||||||||||||||||
| 1948 | - | |||||||||||||||||||||||||
| 1949 | void QNetworkReplyHttpImplPrivate::_q_networkSessionFailed() | - | ||||||||||||||||||||||||
| 1950 | { | - | ||||||||||||||||||||||||
| 1951 | // Abort waiting and working replies. | - | ||||||||||||||||||||||||
| 1952 | if (state == WaitingForSession || state == Working) { | - | ||||||||||||||||||||||||
| 1953 | state = Working; | - | ||||||||||||||||||||||||
| 1954 | QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession()); | - | ||||||||||||||||||||||||
| 1955 | QString errorStr; | - | ||||||||||||||||||||||||
| 1956 | if (session) | - | ||||||||||||||||||||||||
| 1957 | errorStr = session->errorString(); | - | ||||||||||||||||||||||||
| 1958 | else | - | ||||||||||||||||||||||||
| 1959 | errorStr = QCoreApplication::translate("QNetworkReply", "Network session error."); | - | ||||||||||||||||||||||||
| 1960 | error(QNetworkReplyImpl::NetworkSessionFailedError, errorStr); | - | ||||||||||||||||||||||||
| 1961 | finished(); | - | ||||||||||||||||||||||||
| 1962 | } | - | ||||||||||||||||||||||||
| 1963 | } | - | ||||||||||||||||||||||||
| 1964 | - | |||||||||||||||||||||||||
| 1965 | void QNetworkReplyHttpImplPrivate::_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies newPolicies) | - | ||||||||||||||||||||||||
| 1966 | { | - | ||||||||||||||||||||||||
| 1967 | if (request.attribute(QNetworkRequest::BackgroundRequestAttribute).toBool()) { | - | ||||||||||||||||||||||||
| 1968 | if (newPolicies & QNetworkSession::NoBackgroundTrafficPolicy) { | - | ||||||||||||||||||||||||
| 1969 | // Abort waiting and working replies. | - | ||||||||||||||||||||||||
| 1970 | if (state == WaitingForSession || state == Working) { | - | ||||||||||||||||||||||||
| 1971 | state = Working; | - | ||||||||||||||||||||||||
| 1972 | error(QNetworkReply::BackgroundRequestNotAllowedError, | - | ||||||||||||||||||||||||
| 1973 | QCoreApplication::translate("QNetworkReply", "Background request not allowed.")); | - | ||||||||||||||||||||||||
| 1974 | finished(); | - | ||||||||||||||||||||||||
| 1975 | } | - | ||||||||||||||||||||||||
| 1976 | // ### if canResume(), then we could resume automatically | - | ||||||||||||||||||||||||
| 1977 | } | - | ||||||||||||||||||||||||
| 1978 | } | - | ||||||||||||||||||||||||
| 1979 | - | |||||||||||||||||||||||||
| 1980 | } | - | ||||||||||||||||||||||||
| 1981 | #endif | - | ||||||||||||||||||||||||
| 1982 | - | |||||||||||||||||||||||||
| 1983 | - | |||||||||||||||||||||||||
| 1984 | // need to have this function since the reply is a private member variable | - | ||||||||||||||||||||||||
| 1985 | // and the special backends need to access this. | - | ||||||||||||||||||||||||
| 1986 | void QNetworkReplyHttpImplPrivate::emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal) | - | ||||||||||||||||||||||||
| 1987 | { | - | ||||||||||||||||||||||||
| 1988 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 1989 | if (isFinished) | - | ||||||||||||||||||||||||
| 1990 | return; | - | ||||||||||||||||||||||||
| 1991 | - | |||||||||||||||||||||||||
| 1992 | if (!emitAllUploadProgressSignals) { | - | ||||||||||||||||||||||||
| 1993 | //choke signal emissions, except the first and last signals which are unconditional | - | ||||||||||||||||||||||||
| 1994 | if (uploadProgressSignalChoke.isValid()) { | - | ||||||||||||||||||||||||
| 1995 | if (bytesSent != bytesTotal && uploadProgressSignalChoke.elapsed() < progressSignalInterval) { | - | ||||||||||||||||||||||||
| 1996 | return; | - | ||||||||||||||||||||||||
| 1997 | } | - | ||||||||||||||||||||||||
| 1998 | uploadProgressSignalChoke.restart(); | - | ||||||||||||||||||||||||
| 1999 | } else { | - | ||||||||||||||||||||||||
| 2000 | uploadProgressSignalChoke.start(); | - | ||||||||||||||||||||||||
| 2001 | } | - | ||||||||||||||||||||||||
| 2002 | } | - | ||||||||||||||||||||||||
| 2003 | - | |||||||||||||||||||||||||
| 2004 | emit q->uploadProgress(bytesSent, bytesTotal); | - | ||||||||||||||||||||||||
| 2005 | } | - | ||||||||||||||||||||||||
| 2006 | - | |||||||||||||||||||||||||
| 2007 | QNonContiguousByteDevice* QNetworkReplyHttpImplPrivate::createUploadByteDevice() | - | ||||||||||||||||||||||||
| 2008 | { | - | ||||||||||||||||||||||||
| 2009 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 2010 | - | |||||||||||||||||||||||||
| 2011 | if (outgoingDataBuffer) | - | ||||||||||||||||||||||||
| 2012 | uploadByteDevice = QNonContiguousByteDeviceFactory::createShared(outgoingDataBuffer); | - | ||||||||||||||||||||||||
| 2013 | else if (outgoingData) { | - | ||||||||||||||||||||||||
| 2014 | uploadByteDevice = QNonContiguousByteDeviceFactory::createShared(outgoingData); | - | ||||||||||||||||||||||||
| 2015 | } else { | - | ||||||||||||||||||||||||
| 2016 | return 0; | - | ||||||||||||||||||||||||
| 2017 | } | - | ||||||||||||||||||||||||
| 2018 | - | |||||||||||||||||||||||||
| 2019 | // We want signal emissions only for normal asynchronous uploads | - | ||||||||||||||||||||||||
| 2020 | if (!synchronous) | - | ||||||||||||||||||||||||
| 2021 | QObject::connect(uploadByteDevice.data(), SIGNAL(readProgress(qint64,qint64)), | - | ||||||||||||||||||||||||
| 2022 | q, SLOT(emitReplyUploadProgress(qint64,qint64))); | - | ||||||||||||||||||||||||
| 2023 | - | |||||||||||||||||||||||||
| 2024 | return uploadByteDevice.data(); | - | ||||||||||||||||||||||||
| 2025 | } | - | ||||||||||||||||||||||||
| 2026 | - | |||||||||||||||||||||||||
| 2027 | void QNetworkReplyHttpImplPrivate::_q_finished() | - | ||||||||||||||||||||||||
| 2028 | { | - | ||||||||||||||||||||||||
| 2029 | // This gets called queued, just forward to real call then | - | ||||||||||||||||||||||||
| 2030 | finished(); | - | ||||||||||||||||||||||||
| 2031 | } | - | ||||||||||||||||||||||||
| 2032 | - | |||||||||||||||||||||||||
| 2033 | void QNetworkReplyHttpImplPrivate::finished() | - | ||||||||||||||||||||||||
| 2034 | { | - | ||||||||||||||||||||||||
| 2035 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 2036 | - | |||||||||||||||||||||||||
| 2037 | if (state == Finished || state == Aborted || state == WaitingForSession) | - | ||||||||||||||||||||||||
| 2038 | return; | - | ||||||||||||||||||||||||
| 2039 | - | |||||||||||||||||||||||||
| 2040 | QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); | - | ||||||||||||||||||||||||
| 2041 | if (preMigrationDownloaded != Q_INT64_C(-1)) | - | ||||||||||||||||||||||||
| 2042 | totalSize = totalSize.toLongLong() + preMigrationDownloaded; | - | ||||||||||||||||||||||||
| 2043 | - | |||||||||||||||||||||||||
| 2044 | if (manager) { | - | ||||||||||||||||||||||||
| 2045 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||||||||
| 2046 | QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession(); | - | ||||||||||||||||||||||||
| 2047 | if (session && session->state() == QNetworkSession::Roaming && | - | ||||||||||||||||||||||||
| 2048 | state == Working && errorCode != QNetworkReply::OperationCanceledError) { | - | ||||||||||||||||||||||||
| 2049 | // only content with a known size will fail with a temporary network failure error | - | ||||||||||||||||||||||||
| 2050 | if (!totalSize.isNull()) { | - | ||||||||||||||||||||||||
| 2051 | if (bytesDownloaded != totalSize) { | - | ||||||||||||||||||||||||
| 2052 | if (migrateBackend()) { | - | ||||||||||||||||||||||||
| 2053 | // either we are migrating or the request is finished/aborted | - | ||||||||||||||||||||||||
| 2054 | if (state == Reconnecting || state == WaitingForSession) { | - | ||||||||||||||||||||||||
| 2055 | return; // exit early if we are migrating. | - | ||||||||||||||||||||||||
| 2056 | } | - | ||||||||||||||||||||||||
| 2057 | } else { | - | ||||||||||||||||||||||||
| 2058 | error(QNetworkReply::TemporaryNetworkFailureError, | - | ||||||||||||||||||||||||
| 2059 | QNetworkReply::tr("Temporary network failure.")); | - | ||||||||||||||||||||||||
| 2060 | } | - | ||||||||||||||||||||||||
| 2061 | } | - | ||||||||||||||||||||||||
| 2062 | } | - | ||||||||||||||||||||||||
| 2063 | } | - | ||||||||||||||||||||||||
| 2064 | #endif | - | ||||||||||||||||||||||||
| 2065 | } | - | ||||||||||||||||||||||||
| 2066 | - | |||||||||||||||||||||||||
| 2067 | // if we don't know the total size of or we received everything save the cache | - | ||||||||||||||||||||||||
| 2068 | if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize) | - | ||||||||||||||||||||||||
| 2069 | completeCacheSave(); | - | ||||||||||||||||||||||||
| 2070 | - | |||||||||||||||||||||||||
| 2071 | // We check for errorCode too as in case of SSL handshake failure, we still | - | ||||||||||||||||||||||||
| 2072 | // get the HTTP redirect status code (301, 303 etc) | - | ||||||||||||||||||||||||
| 2073 | if (isHttpRedirectResponse() && errorCode == QNetworkReply::NoError) | - | ||||||||||||||||||||||||
| 2074 | return; | - | ||||||||||||||||||||||||
| 2075 | - | |||||||||||||||||||||||||
| 2076 | state = Finished; | - | ||||||||||||||||||||||||
| 2077 | q->setFinished(true); | - | ||||||||||||||||||||||||
| 2078 | - | |||||||||||||||||||||||||
| 2079 | if (totalSize.isNull() || totalSize == -1) { | - | ||||||||||||||||||||||||
| 2080 | emit q->downloadProgress(bytesDownloaded, bytesDownloaded); | - | ||||||||||||||||||||||||
| 2081 | } else { | - | ||||||||||||||||||||||||
| 2082 | emit q->downloadProgress(bytesDownloaded, totalSize.toLongLong()); | - | ||||||||||||||||||||||||
| 2083 | } | - | ||||||||||||||||||||||||
| 2084 | - | |||||||||||||||||||||||||
| 2085 | if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer)) | - | ||||||||||||||||||||||||
| 2086 | emit q->uploadProgress(0, 0); | - | ||||||||||||||||||||||||
| 2087 | - | |||||||||||||||||||||||||
| 2088 | emit q->readChannelFinished(); | - | ||||||||||||||||||||||||
| 2089 | emit q->finished(); | - | ||||||||||||||||||||||||
| 2090 | } | - | ||||||||||||||||||||||||
| 2091 | - | |||||||||||||||||||||||||
| 2092 | void QNetworkReplyHttpImplPrivate::_q_error(QNetworkReplyImpl::NetworkError code, const QString &errorMessage) | - | ||||||||||||||||||||||||
| 2093 | { | - | ||||||||||||||||||||||||
| 2094 | this->error(code, errorMessage); | - | ||||||||||||||||||||||||
| 2095 | } | - | ||||||||||||||||||||||||
| 2096 | - | |||||||||||||||||||||||||
| 2097 | - | |||||||||||||||||||||||||
| 2098 | void QNetworkReplyHttpImplPrivate::error(QNetworkReplyImpl::NetworkError code, const QString &errorMessage) | - | ||||||||||||||||||||||||
| 2099 | { | - | ||||||||||||||||||||||||
| 2100 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 2101 | // Can't set and emit multiple errors. | - | ||||||||||||||||||||||||
| 2102 | if (errorCode != QNetworkReply::NoError) { | - | ||||||||||||||||||||||||
| 2103 | qWarning("QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once."); | - | ||||||||||||||||||||||||
| 2104 | return; | - | ||||||||||||||||||||||||
| 2105 | } | - | ||||||||||||||||||||||||
| 2106 | - | |||||||||||||||||||||||||
| 2107 | errorCode = code; | - | ||||||||||||||||||||||||
| 2108 | q->setErrorString(errorMessage); | - | ||||||||||||||||||||||||
| 2109 | - | |||||||||||||||||||||||||
| 2110 | // note: might not be a good idea, since users could decide to delete us | - | ||||||||||||||||||||||||
| 2111 | // which would delete the backend too... | - | ||||||||||||||||||||||||
| 2112 | // maybe we should protect the backend | - | ||||||||||||||||||||||||
| 2113 | emit q->error(code); | - | ||||||||||||||||||||||||
| 2114 | } | - | ||||||||||||||||||||||||
| 2115 | - | |||||||||||||||||||||||||
| 2116 | void QNetworkReplyHttpImplPrivate::_q_metaDataChanged() | - | ||||||||||||||||||||||||
| 2117 | { | - | ||||||||||||||||||||||||
| 2118 | // FIXME merge this with replyDownloadMetaData(); ? | - | ||||||||||||||||||||||||
| 2119 | - | |||||||||||||||||||||||||
| 2120 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 2121 | // 1. do we have cookies? | - | ||||||||||||||||||||||||
| 2122 | // 2. are we allowed to set them? | - | ||||||||||||||||||||||||
| 2123 | if (manager) {
| 0-814 | ||||||||||||||||||||||||
| 2124 | const auto it = cookedHeaders.containsconstFind(QNetworkRequest::SetCookieHeader) && manager); | - | ||||||||||||||||||||||||
| 2125 | &&if (static_cast<QNetworkRequest::LoadControl>it != cookedHeaders.cend()
| 13-801 | ||||||||||||||||||||||||
| 2126 | (&& request.attribute(QNetworkRequest::CookieSaveControlAttribute,
| 0-13 | ||||||||||||||||||||||||
| ||||||||||||||||||||||||||
| 2127 |
| 0-13 | ||||||||||||||||||||||||
| ||||||||||||||||||||||||||
| 2128 | QNetworkCookieJar *jar = manager->cookieJar(); | - | ||||||||||||||||||||||||
| 2129 | if (jar) {
| 0-13 | ||||||||||||||||||||||||
| 2130 | QList<QNetworkCookie> cookies = | - | ||||||||||||||||||||||||
| 2131 | qvariant_cast<QList<QNetworkCookie> >(cookedHeadersit.value(QNetworkRequest::SetCookieHeader)); | - | ||||||||||||||||||||||||
| QNetworkCookieJar *jar = manager->cookieJar(); | ||||||||||||||||||||||||||
| if (jar) | ||||||||||||||||||||||||||
| ()); | ||||||||||||||||||||||||||
| 2132 | jar->setCookiesFromUrl(cookies, url); | - | ||||||||||||||||||||||||
| 2133 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 2134 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 2135 | } executed 814 times by 6 tests: end of blockExecuted by:
| 814 | ||||||||||||||||||||||||
| 2136 | emit q->metaDataChanged(); | - | ||||||||||||||||||||||||
| 2137 | } executed 814 times by 6 tests: end of blockExecuted by:
| 814 | ||||||||||||||||||||||||
| 2138 | - | |||||||||||||||||||||||||
| 2139 | /* | - | ||||||||||||||||||||||||
| 2140 | Migrates the backend of the QNetworkReply to a new network connection if required. Returns | - | ||||||||||||||||||||||||
| 2141 | true if the reply is migrated or it is not required; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 2142 | */ | - | ||||||||||||||||||||||||
| 2143 | bool QNetworkReplyHttpImplPrivate::migrateBackend() | - | ||||||||||||||||||||||||
| 2144 | { | - | ||||||||||||||||||||||||
| 2145 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||||||||
| 2146 | - | |||||||||||||||||||||||||
| 2147 | // Network reply is already finished or aborted, don't need to migrate. | - | ||||||||||||||||||||||||
| 2148 | if (state == Finished || state == Aborted) | - | ||||||||||||||||||||||||
| 2149 | return true; | - | ||||||||||||||||||||||||
| 2150 | - | |||||||||||||||||||||||||
| 2151 | // Backend does not support resuming download. | - | ||||||||||||||||||||||||
| 2152 | if (!canResume()) | - | ||||||||||||||||||||||||
| 2153 | return false; | - | ||||||||||||||||||||||||
| 2154 | - | |||||||||||||||||||||||||
| 2155 | // Request has outgoing data, not migrating. | - | ||||||||||||||||||||||||
| 2156 | if (outgoingData) | - | ||||||||||||||||||||||||
| 2157 | return false; | - | ||||||||||||||||||||||||
| 2158 | - | |||||||||||||||||||||||||
| 2159 | // Request is serviced from the cache, don't need to migrate. | - | ||||||||||||||||||||||||
| 2160 | if (cacheLoadDevice) | - | ||||||||||||||||||||||||
| 2161 | return true; | - | ||||||||||||||||||||||||
| 2162 | - | |||||||||||||||||||||||||
| 2163 | state = Reconnecting; | - | ||||||||||||||||||||||||
| 2164 | - | |||||||||||||||||||||||||
| 2165 | cookedHeaders.clear(); | - | ||||||||||||||||||||||||
| 2166 | rawHeaders.clear(); | - | ||||||||||||||||||||||||
| 2167 | - | |||||||||||||||||||||||||
| 2168 | preMigrationDownloaded = bytesDownloaded; | - | ||||||||||||||||||||||||
| 2169 | - | |||||||||||||||||||||||||
| 2170 | setResumeOffset(bytesDownloaded); | - | ||||||||||||||||||||||||
| 2171 | - | |||||||||||||||||||||||||
| 2172 | emit q->abortHttpRequest(); | - | ||||||||||||||||||||||||
| 2173 | - | |||||||||||||||||||||||||
| 2174 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 2175 | - | |||||||||||||||||||||||||
| 2176 | return true; | - | ||||||||||||||||||||||||
| 2177 | } | - | ||||||||||||||||||||||||
| 2178 | - | |||||||||||||||||||||||||
| 2179 | - | |||||||||||||||||||||||||
| 2180 | void QNetworkReplyHttpImplPrivate::createCache() | - | ||||||||||||||||||||||||
| 2181 | { | - | ||||||||||||||||||||||||
| 2182 | // check if we can save and if we're allowed to | - | ||||||||||||||||||||||||
| 2183 | if (!managerPrivate->networkCache | - | ||||||||||||||||||||||||
| 2184 | || !request.attribute(QNetworkRequest::CacheSaveControlAttribute, true).toBool()) | - | ||||||||||||||||||||||||
| 2185 | return; | - | ||||||||||||||||||||||||
| 2186 | cacheEnabled = true; | - | ||||||||||||||||||||||||
| 2187 | } | - | ||||||||||||||||||||||||
| 2188 | - | |||||||||||||||||||||||||
| 2189 | bool QNetworkReplyHttpImplPrivate::isCachingEnabled() const | - | ||||||||||||||||||||||||
| 2190 | { | - | ||||||||||||||||||||||||
| 2191 | return (cacheEnabled && managerPrivate->networkCache != 0); | - | ||||||||||||||||||||||||
| 2192 | } | - | ||||||||||||||||||||||||
| 2193 | - | |||||||||||||||||||||||||
| 2194 | void QNetworkReplyHttpImplPrivate::setCachingEnabled(bool enable) | - | ||||||||||||||||||||||||
| 2195 | { | - | ||||||||||||||||||||||||
| 2196 | if (!enable && !cacheEnabled)
| 0-787 | ||||||||||||||||||||||||
| 2197 | return; // nothing to do executed 27 times by 2 tests: return;Executed by:
| 27 | ||||||||||||||||||||||||
| 2198 | if (enable && cacheEnabled)
| 0-787 | ||||||||||||||||||||||||
| 2199 | return; // nothing to do either! never executed: return; | 0 | ||||||||||||||||||||||||
| 2200 | - | |||||||||||||||||||||||||
| 2201 | if (enable) {
| 0-787 | ||||||||||||||||||||||||
| 2202 | if (Q_UNLIKELY(bytesDownloaded))) {
| 0-787 | ||||||||||||||||||||||||
| 2203 | qDebug() << "setCachingEnabled: " << bytesDownloaded << " bytesDownloaded"; | - | ||||||||||||||||||||||||
| 2204 | // refuse to enable in this case | - | ||||||||||||||||||||||||
| 2205 | qCritical("QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written"); | - | ||||||||||||||||||||||||
| 2206 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2207 | } | - | ||||||||||||||||||||||||
| 2208 | - | |||||||||||||||||||||||||
| 2209 | createCache(); | - | ||||||||||||||||||||||||
| 2210 | } else { executed 787 times by 6 tests: end of blockExecuted by:
| 787 | ||||||||||||||||||||||||
| 2211 | // someone told us to turn on, then back off? | - | ||||||||||||||||||||||||
| 2212 | // ok... but you should make up your mind | - | ||||||||||||||||||||||||
| 2213 | qDebug("QNetworkReplyImpl: setCachingEnabled(true) called after setCachingEnabled(false)"); | - | ||||||||||||||||||||||||
| 2214 | managerPrivate->networkCache->remove(url); | - | ||||||||||||||||||||||||
| 2215 | cacheSaveDevice = 0; | - | ||||||||||||||||||||||||
| 2216 | cacheEnabled = false; | - | ||||||||||||||||||||||||
| 2217 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2218 | } | - | ||||||||||||||||||||||||
| 2219 | - | |||||||||||||||||||||||||
| 2220 | bool QNetworkReplyHttpImplPrivate::isCachingAllowed() const | - | ||||||||||||||||||||||||
| 2221 | { | - | ||||||||||||||||||||||||
| 2222 | return operation == QNetworkAccessManager::GetOperation || operation == QNetworkAccessManager::HeadOperation; | - | ||||||||||||||||||||||||
| 2223 | } | - | ||||||||||||||||||||||||
| 2224 | - | |||||||||||||||||||||||||
| 2225 | void QNetworkReplyHttpImplPrivate::completeCacheSave() | - | ||||||||||||||||||||||||
| 2226 | { | - | ||||||||||||||||||||||||
| 2227 | if (cacheEnabled && errorCode != QNetworkReplyImpl::NoError) { | - | ||||||||||||||||||||||||
| 2228 | managerPrivate->networkCache->remove(url); | - | ||||||||||||||||||||||||
| 2229 | } else if (cacheEnabled && cacheSaveDevice) { | - | ||||||||||||||||||||||||
| 2230 | managerPrivate->networkCache->insert(cacheSaveDevice); | - | ||||||||||||||||||||||||
| 2231 | } | - | ||||||||||||||||||||||||
| 2232 | cacheSaveDevice = 0; | - | ||||||||||||||||||||||||
| 2233 | cacheEnabled = false; | - | ||||||||||||||||||||||||
| 2234 | } | - | ||||||||||||||||||||||||
| 2235 | - | |||||||||||||||||||||||||
| 2236 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 2237 | - | |||||||||||||||||||||||||
| 2238 | #endif // QT_NO_HTTP | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |