diff options
Diffstat (limited to 'src/network/access/qnetworkreplyimpl.cpp')
-rw-r--r-- | src/network/access/qnetworkreplyimpl.cpp | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 07a5bf3..128d18f 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -478,6 +478,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) @@ -487,36 +518,12 @@ 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; for (int i = 0; i < data.bufferCount(); i++) { - QByteArray item = data[i]; + QByteArray const &item = data[i]; if (cacheSaveDevice) cacheSaveDevice->write(item.constData(), item.size()); @@ -529,6 +536,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); @@ -572,6 +586,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); |