diff options
-rw-r--r-- | src/network/access/qnetworkreplyimpl.cpp | 73 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyimpl_p.h | 5 |
2 files changed, 53 insertions, 25 deletions
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 320b1ac..4f35358 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -403,6 +403,37 @@ qint64 QNetworkReplyImplPrivate::nextDownstreamBlockSize() const return qMax<qint64>(0, readBufferMaxSize - readBuffer.byteAmount()); } +void QNetworkReplyImplPrivate::initCacheSaveDevice() +{ + Q_Q(QNetworkReplyImpl); + + // save the meta data + QNetworkCacheMetaData metaData; + metaData.setUrl(url); + metaData = backend->fetchCacheMetaData(metaData); + + // save the redirect request also in the cache + QVariant redirectionTarget = q->attribute(QNetworkRequest::RedirectionTargetAttribute); + if (redirectionTarget.isValid()) { + QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes(); + attributes.insert(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget); + metaData.setAttributes(attributes); + } + + cacheSaveDevice = networkCache()->prepare(metaData); + + if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) { + if (cacheSaveDevice && !cacheSaveDevice->isOpen()) + qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- " + "class %s probably needs to be fixed", + networkCache()->metaObject()->className()); + + networkCache()->remove(url); + cacheSaveDevice = 0; + cacheEnabled = false; + } +} + // we received downstream data and send this to the cache // and to our readBuffer (which in turn gets read by the user of QNetworkReply) void QNetworkReplyImplPrivate::appendDownstreamData(QByteDataBuffer &data) @@ -412,31 +443,7 @@ void QNetworkReplyImplPrivate::appendDownstreamData(QByteDataBuffer &data) return; if (cacheEnabled && !cacheSaveDevice) { - // save the meta data - QNetworkCacheMetaData metaData; - metaData.setUrl(url); - metaData = backend->fetchCacheMetaData(metaData); - - // save the redirect request also in the cache - QVariant redirectionTarget = q->attribute(QNetworkRequest::RedirectionTargetAttribute); - if (redirectionTarget.isValid()) { - QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes(); - attributes.insert(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget); - metaData.setAttributes(attributes); - } - - cacheSaveDevice = networkCache()->prepare(metaData); - - if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) { - if (cacheSaveDevice && !cacheSaveDevice->isOpen()) - qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- " - "class %s probably needs to be fixed", - networkCache()->metaObject()->className()); - - networkCache()->remove(url); - cacheSaveDevice = 0; - cacheEnabled = false; - } + initCacheSaveDevice(); } qint64 bytesWritten = 0; @@ -454,6 +461,13 @@ void QNetworkReplyImplPrivate::appendDownstreamData(QByteDataBuffer &data) bytesDownloaded += bytesWritten; lastBytesDownloaded = bytesDownloaded; + appendDownstreamDataSignalEmissions(); +} + +void QNetworkReplyImplPrivate::appendDownstreamDataSignalEmissions() +{ + Q_Q(QNetworkReplyImpl); + QPointer<QNetworkReplyImpl> qq = q; QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); @@ -495,6 +509,15 @@ void QNetworkReplyImplPrivate::appendDownstreamData(QIODevice *data) _q_copyReadyRead(); } +void QNetworkReplyImplPrivate::appendDownstreamData(const QByteArray &data) +{ + // TODO implement + + // TODO call + + qFatal("QNetworkReplyImplPrivate::appendDownstreamData not implemented"); +} + void QNetworkReplyImplPrivate::finished() { Q_Q(QNetworkReplyImpl); diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 168e5cf..a7a568a 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -145,8 +145,13 @@ public: void consume(qint64 count); void emitUploadProgress(qint64 bytesSent, qint64 bytesTotal); qint64 nextDownstreamBlockSize() const; + + void initCacheSaveDevice(); + void appendDownstreamDataSignalEmissions(); void appendDownstreamData(QByteDataBuffer &data); void appendDownstreamData(QIODevice *data); + void appendDownstreamData(const QByteArray &data); + void finished(); void error(QNetworkReply::NetworkError code, const QString &errorString); void metaDataChanged(); |