本文整理汇总了C++中qnetworkcachemetadata::RawHeaderList::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ RawHeaderList::begin方法的具体用法?C++ RawHeaderList::begin怎么用?C++ RawHeaderList::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qnetworkcachemetadata::RawHeaderList
的用法示例。
在下文中一共展示了RawHeaderList::begin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetLastModified
/** \fn MythDownloadManager::GetLastModified(const QString &url)
* \brief Gets the Last Modified timestamp for a URI
* \param url URI to test.
* \return Timestamp the URI was last modified or now if an error occurred
*/
QDateTime MythDownloadManager::GetLastModified(const QString &url)
{
static const char dateFormat[] = "ddd, dd MMM yyyy hh:mm:ss 'GMT'";
VERBOSE(VB_FILE+VB_EXTRA, LOC + QString("GetLastModified('%1')").arg(url));
QDateTime result;
QDateTime now = QDateTime::currentDateTime();
QNetworkCacheMetaData urlData = m_manager->cache()->metaData(QUrl(url));
if (urlData.isValid())
{
if (urlData.lastModified().secsTo(now) <= 60)
{
result = urlData.lastModified();
}
else
{
// If the last modification date is older than 60 seconds, and
// we loaded the page over 60 seconds ago, then redownload the
// page to re-verify it's last modified date.
QNetworkCacheMetaData::RawHeaderList headers =
urlData.rawHeaders();
bool found = false;
QNetworkCacheMetaData::RawHeaderList::iterator it
= headers.begin();
for (; !found && it != headers.end(); ++it)
{
if ((*it).first == "Date")
{
found = true;
QDateTime loadDate =
QDateTime::fromString((*it).second, dateFormat);
loadDate.setTimeSpec(Qt::UTC);
if (loadDate.secsTo(now) <= 60)
result = urlData.lastModified();
}
}
}
}
if (!result.isValid())
{
MythDownloadInfo *dlInfo = new MythDownloadInfo;
dlInfo->m_url = url;
dlInfo->m_syncMode = true;
if (downloadNow(dlInfo, false) && dlInfo->m_reply)
{
QVariant lastMod =
dlInfo->m_reply->header(QNetworkRequest::LastModifiedHeader);
if (lastMod.isValid())
result = lastMod.toDateTime();
}
delete dlInfo;
}
return result;
}
示例2: downloadQNetworkRequest
/** \fn MythDownloadManager::downloadQNetworkRequest(MythDownloadInfo *dlInfo)
* \brief Downloads a QNetworkRequest via the QNetworkAccessManager
* \param dlInfo MythDownloadInfo information for download
*/
void MythDownloadManager::downloadQNetworkRequest(MythDownloadInfo *dlInfo)
{
static const char dateFormat[] = "ddd, dd MMM yyyy hh:mm:ss 'GMT'";
QUrl qurl(dlInfo->m_url);
QNetworkRequest request;
if (dlInfo->m_request)
{
request = *dlInfo->m_request;
delete dlInfo->m_request;
dlInfo->m_request = NULL;
}
else
request.setUrl(qurl);
if (!dlInfo->m_reload)
{
// Prefer the in-cache item if one exists and it is less than 60
// seconds old and has not expired in the last 10 seconds.
QDateTime now = QDateTime::currentDateTime();
QNetworkCacheMetaData urlData = m_manager->cache()->metaData(qurl);
if ((urlData.isValid()) &&
((!urlData.expirationDate().isValid()) ||
(urlData.expirationDate().secsTo(now) < 10)))
{
QNetworkCacheMetaData::RawHeaderList headers =
urlData.rawHeaders();
bool found = false;
QNetworkCacheMetaData::RawHeaderList::iterator it
= headers.begin();
for (; !found && it != headers.end(); ++it)
{
if ((*it).first == "Date")
{
found = true;
QDateTime loadDate =
QDateTime::fromString((*it).second, dateFormat);
loadDate.setTimeSpec(Qt::UTC);
if (loadDate.secsTo(now) < 60)
dlInfo->m_preferCache = true;
}
}
}
}
if (dlInfo->m_preferCache)
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::PreferCache);
request.setRawHeader("User-Agent",
"MythDownloadManager v" MYTH_BINARY_VERSION);
if (dlInfo->m_post)
dlInfo->m_reply = m_manager->post(request, *dlInfo->m_data);
else
dlInfo->m_reply = m_manager->get(request);
m_downloadReplies[dlInfo->m_reply] = dlInfo;
connect(dlInfo->m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this,
SLOT(downloadError(QNetworkReply::NetworkError)));
connect(dlInfo->m_reply, SIGNAL(downloadProgress(qint64, qint64)),
this, SLOT(downloadProgress(qint64, qint64)));
}