Skip to content

Commit

Permalink
[bugfix] Do not cache invalid WM(T)S responses
Browse files Browse the repository at this point in the history
The problem here was that in case of http->https redirect
from a misconfigured server (that advertizes http and then
redirects all request to https) all http redirect requests
were cached, making all subsequent requests to the same
url hit the 301 Moved Permanently reponse page intead of
the redirected content.

Fixes #16427 WMTS rendering problems in 2.18 and Master

cherry-picked from d102404
  • Loading branch information
elpaso committed Oct 4, 2017
1 parent f14502e commit b09fb37
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/providers/wms/qgstilecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ void QgsTileCache::insertTile( const QUrl& url, const QImage& image )
bool QgsTileCache::tile( const QUrl& url, QImage& image )
{
QMutexLocker locker( &sTileCacheMutex );
if ( QImage* i = sTileCache.object( url ) )
bool success = false;
if ( QImage *i = sTileCache.object( url ) )
{
image = *i;
return true;
success = true;
}
else if ( QgsNetworkAccessManager::instance()->cache()->metaData( url ).isValid() )
{
Expand All @@ -48,10 +49,13 @@ bool QgsTileCache::tile( const QUrl& url, QImage& image )
image = QImage::fromData( imageData );

// cache it as well (mutex is already locked)
sTileCache.insert( url, new QImage( image ) );

return true;
// Check for null because it could be a redirect (see: https://issues.qgis.org/issues/16427 )
if ( ! image.isNull( ) )
{
sTileCache.insert( url, new QImage( image ) );
success = true;
}
}
}
return false;
return success;
}

0 comments on commit b09fb37

Please sign in to comment.