本文整理汇总了C++中QAbstractNetworkCache::metaData方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractNetworkCache::metaData方法的具体用法?C++ QAbstractNetworkCache::metaData怎么用?C++ QAbstractNetworkCache::metaData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractNetworkCache
的用法示例。
在下文中一共展示了QAbstractNetworkCache::metaData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: networkFinished
void QGeoMapReplyNokia::networkFinished()
{
if (!m_reply)
return;
if (m_reply->error() != QNetworkReply::NoError)
return;
QVariant fromCache = m_reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute);
setCached(fromCache.toBool());
if (!isCached()) {
QAbstractNetworkCache *cache = m_reply->manager()->cache();
if (cache) {
QNetworkCacheMetaData metaData = cache->metaData(m_reply->url());
QDateTime exp = QDateTime::currentDateTime();
exp = exp.addDays(14);
metaData.setExpirationDate(exp);
cache->updateMetaData(metaData);
}
}
setMapImageData(m_reply->readAll());
setMapImageFormat("PNG");
setFinished(true);
m_reply->deleteLater();
m_reply = 0;
}
示例2: sendCacheContents
bool QNetworkAccessCacheBackend::sendCacheContents()
{
setCachingEnabled(false);
QAbstractNetworkCache *nc = networkCache();
if (!nc)
return false;
QNetworkCacheMetaData item = nc->metaData(url());
if (!item.isValid())
return false;
QNetworkCacheMetaData::AttributesMap attributes = item.attributes();
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, attributes.value(QNetworkRequest::HttpStatusCodeAttribute));
setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, attributes.value(QNetworkRequest::HttpReasonPhraseAttribute));
// set the raw headers
QNetworkCacheMetaData::RawHeaderList rawHeaders = item.rawHeaders();
QNetworkCacheMetaData::RawHeaderList::ConstIterator it = rawHeaders.constBegin(),
end = rawHeaders.constEnd();
for ( ; it != end; ++it) {
if (it->first.toLower() == "cache-control" &&
it->second.toLower().contains("must-revalidate")) {
return false;
}
setRawHeader(it->first, it->second);
}
// handle a possible redirect
QVariant redirectionTarget = attributes.value(QNetworkRequest::RedirectionTargetAttribute);
if (redirectionTarget.isValid()) {
setAttribute(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget);
redirectionRequested(redirectionTarget.toUrl());
}
// signal we're open
metaDataChanged();
if (operation() == QNetworkAccessManager::GetOperation) {
QIODevice *contents = nc->data(url());
if (!contents)
return false;
contents->setParent(this);
writeDownstreamData(contents);
}
#if defined(QNETWORKACCESSCACHEBACKEND_DEBUG)
qDebug() << "Successfully sent cache:" << url();
#endif
return true;
}
示例3: willLoadFromCache
bool ResourceHandle::willLoadFromCache(ResourceRequest& request, Frame* frame)
{
if (!frame)
return false;
QNetworkAccessManager* manager = QWebFramePrivate::kit(frame)->page()->networkAccessManager();
QAbstractNetworkCache* cache = manager->cache();
if (!cache)
return false;
QNetworkCacheMetaData data = cache->metaData(request.url());
if (data.isValid()) {
request.setCachePolicy(ReturnCacheDataDontLoad);
return true;
}
return false;
}
示例4: willLoadFromCache
bool ResourceHandle::willLoadFromCache(ResourceRequest& request, Frame* frame)
{
if (!frame)
return false;
QNetworkAccessManager* manager = 0;
QAbstractNetworkCache* cache = 0;
if (frame->loader()->networkingContext()) {
manager = frame->loader()->networkingContext()->networkAccessManager();
cache = manager->cache();
}
if (!cache)
return false;
QNetworkCacheMetaData data = cache->metaData(request.url());
if (data.isValid()) {
request.setCachePolicy(ReturnCacheDataDontLoad);
return true;
}
return false;
}
示例5: loadFromCacheIfAllowed
/*
For a given httpRequest
1) If AlwaysNetwork, return
2) If we have a cache entry for this url populate headers so the server can return 304
3) Calculate if response_is_fresh and if so send the cache and set loadedFromCache to true
*/
bool QNetworkAccessHttpBackend::loadFromCacheIfAllowed(QHttpNetworkRequest &httpRequest)
{
QNetworkRequest::CacheLoadControl CacheLoadControlAttribute =
(QNetworkRequest::CacheLoadControl)request().attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt();
if (CacheLoadControlAttribute == QNetworkRequest::AlwaysNetwork) {
// If the request does not already specify preferred cache-control
// force reload from the network and tell any caching proxy servers to reload too
if (!request().rawHeaderList().contains("Cache-Control")) {
httpRequest.setHeaderField("Cache-Control", "no-cache");
httpRequest.setHeaderField("Pragma", "no-cache");
}
return false;
}
// The disk cache API does not currently support partial content retrieval.
// That is why we don't use the disk cache for any such requests.
if (request().hasRawHeader("Range"))
return false;
QAbstractNetworkCache *nc = networkCache();
if (!nc)
return false; // no local cache
QNetworkCacheMetaData metaData = nc->metaData(url());
if (!metaData.isValid())
return false; // not in cache
if (!metaData.saveToDisk())
return false;
QNetworkHeadersPrivate cacheHeaders;
QNetworkHeadersPrivate::RawHeadersList::ConstIterator it;
cacheHeaders.setAllRawHeaders(metaData.rawHeaders());
it = cacheHeaders.findRawHeader("etag");
if (it != cacheHeaders.rawHeaders.constEnd())
httpRequest.setHeaderField("If-None-Match", it->second);
QDateTime lastModified = metaData.lastModified();
if (lastModified.isValid())
httpRequest.setHeaderField("If-Modified-Since", QNetworkHeadersPrivate::toHttpDate(lastModified));
it = cacheHeaders.findRawHeader("Cache-Control");
if (it != cacheHeaders.rawHeaders.constEnd()) {
QHash<QByteArray, QByteArray> cacheControl = parseHttpOptionHeader(it->second);
if (cacheControl.contains("must-revalidate"))
return false;
}
QDateTime currentDateTime = QDateTime::currentDateTime();
QDateTime expirationDate = metaData.expirationDate();
#if 0
/*
* age_value
* is the value of Age: header received by the cache with
* this response.
* date_value
* is the value of the origin server's Date: header
* request_time
* is the (local) time when the cache made the request
* that resulted in this cached response
* response_time
* is the (local) time when the cache received the
* response
* now
* is the current (local) time
*/
int age_value = 0;
it = cacheHeaders.findRawHeader("age");
if (it != cacheHeaders.rawHeaders.constEnd())
age_value = it->second.toInt();
QDateTime dateHeader;
int date_value = 0;
it = cacheHeaders.findRawHeader("date");
if (it != cacheHeaders.rawHeaders.constEnd()) {
dateHeader = QNetworkHeadersPrivate::fromHttpDate(it->second);
date_value = dateHeader.toTime_t();
}
int now = currentDateTime.toUTC().toTime_t();
int request_time = now;
int response_time = now;
// Algorithm from RFC 2616 section 13.2.3
int apparent_age = qMax(0, response_time - date_value);
int corrected_received_age = qMax(apparent_age, age_value);
int response_delay = response_time - request_time;
int corrected_initial_age = corrected_received_age + response_delay;
int resident_time = now - response_time;
int current_age = corrected_initial_age + resident_time;
// RFC 2616 13.2.4 Expiration Calculations
//.........这里部分代码省略.........