本文整理汇总了C++中QNetworkCacheMetaData::setRawHeaders方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkCacheMetaData::setRawHeaders方法的具体用法?C++ QNetworkCacheMetaData::setRawHeaders怎么用?C++ QNetworkCacheMetaData::setRawHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkCacheMetaData
的用法示例。
在下文中一共展示了QNetworkCacheMetaData::setRawHeaders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: replyFinished
void QgsWfsRequest::replyFinished()
{
if ( !mIsAborted && mReply )
{
if ( mReply->error() == QNetworkReply::NoError )
{
QgsDebugMsgLevel( QStringLiteral( "reply OK" ), 4 );
QVariant redirect = mReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
if ( !redirect.isNull() )
{
QgsDebugMsgLevel( QStringLiteral( "Request redirected." ), 4 );
const QUrl &toUrl = redirect.toUrl();
mReply->request();
if ( toUrl == mReply->url() )
{
mErrorMessage = tr( "Redirect loop detected: %1" ).arg( toUrl.toString() );
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
mResponse.clear();
}
else
{
QNetworkRequest request( toUrl );
QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsWfsRequest" ) );
if ( !mUri.auth().setAuthorization( request ) )
{
mResponse.clear();
mErrorMessage = errorMessageFailedAuth();
mErrorCode = QgsWfsRequest::NetworkError;
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
emit downloadFinished();
return;
}
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, mForceRefresh ? QNetworkRequest::AlwaysNetwork : QNetworkRequest::PreferCache );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
mReply->deleteLater();
mReply = nullptr;
QgsDebugMsgLevel( QStringLiteral( "redirected: %1 forceRefresh=%2" ).arg( redirect.toString() ).arg( mForceRefresh ), 4 );
mReply = QgsNetworkAccessManager::instance()->get( request );
mReply->setReadBufferSize( READ_BUFFER_SIZE_HINT );
if ( !mUri.auth().setAuthorizationReply( mReply ) )
{
mResponse.clear();
mErrorMessage = errorMessageFailedAuth();
mErrorCode = QgsWfsRequest::NetworkError;
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
emit downloadFinished();
return;
}
connect( mReply, &QNetworkReply::finished, this, &QgsWfsRequest::replyFinished, Qt::DirectConnection );
connect( mReply, &QNetworkReply::downloadProgress, this, &QgsWfsRequest::replyProgress, Qt::DirectConnection );
return;
}
}
else
{
const QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
if ( nam->cache() )
{
QNetworkCacheMetaData cmd = nam->cache()->metaData( mReply->request().url() );
QNetworkCacheMetaData::RawHeaderList hl;
const auto constRawHeaders = cmd.rawHeaders();
for ( const QNetworkCacheMetaData::RawHeader &h : constRawHeaders )
{
if ( h.first != "Cache-Control" )
hl.append( h );
}
cmd.setRawHeaders( hl );
QgsDebugMsgLevel( QStringLiteral( "expirationDate:%1" ).arg( cmd.expirationDate().toString() ), 4 );
if ( cmd.expirationDate().isNull() )
{
cmd.setExpirationDate( QDateTime::currentDateTime().addSecs( defaultExpirationInSec() ) );
}
nam->cache()->updateMetaData( cmd );
}
else
{
QgsDebugMsgLevel( QStringLiteral( "No cache!" ), 4 );
}
#ifdef QGISDEBUG
bool fromCache = mReply->attribute( QNetworkRequest::SourceIsFromCacheAttribute ).toBool();
QgsDebugMsgLevel( QStringLiteral( "Reply was cached: %1" ).arg( fromCache ), 4 );
#endif
mResponse = mReply->readAll();
if ( mResponse.isEmpty() && !mGotNonEmptyResponse )
{
mErrorMessage = tr( "empty response: %1" ).arg( mReply->errorString() );
mErrorCode = QgsWfsRequest::ServerExceptionError;
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
}
}
//.........这里部分代码省略.........