Skip to content

Commit

Permalink
WMS provider: protect from simple redirect loops in GetCapabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Santilli committed Mar 8, 2013
1 parent 4bdfb84 commit 6795aef
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,26 +1451,37 @@ void QgsWmsProvider::capabilitiesReplyFinished()
{
emit statusChanged( tr( "Capabilities request redirected." ) );

QNetworkRequest request( redirect.toUrl() );
setAuthorization( request );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );

mCapabilitiesReply->deleteLater();
QgsDebugMsg( QString( "redirected getcapabilities: %1" ).arg( redirect.toString() ) );
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );

connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
return;
const QUrl& toUrl = redirect.toUrl();
mCapabilitiesReply->request();
if ( toUrl == mCapabilitiesReply->url() ) {
mErrorFormat = "text/plain";
mError = tr( "Redirect loop detected: %1" ).arg( toUrl.toString() );
QgsMessageLog::logMessage( mError, tr( "WMS" ) );
mHttpCapabilitiesResponse.clear();
} else {
QNetworkRequest request( toUrl );
setAuthorization( request );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );

mCapabilitiesReply->deleteLater();
QgsDebugMsg( QString( "redirected getcapabilities: %1" ).arg( redirect.toString() ) );
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );

connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
return;
}
}

mHttpCapabilitiesResponse = mCapabilitiesReply->readAll();

if ( mHttpCapabilitiesResponse.isEmpty() )
else
{
mErrorFormat = "text/plain";
mError = tr( "empty of capabilities: %1" ).arg( mCapabilitiesReply->errorString() );
mHttpCapabilitiesResponse = mCapabilitiesReply->readAll();

if ( mHttpCapabilitiesResponse.isEmpty() )
{
mErrorFormat = "text/plain";
mError = tr( "empty of capabilities: %1" ).arg( mCapabilitiesReply->errorString() );
}
}
}
else
Expand All @@ -1481,7 +1492,6 @@ void QgsWmsProvider::capabilitiesReplyFinished()
mHttpCapabilitiesResponse.clear();
}


mCapabilitiesReply->deleteLater();
mCapabilitiesReply = 0;
}
Expand Down

0 comments on commit 6795aef

Please sign in to comment.