Allow remote SVG files with text/plain MIME type, instead of only

valid image/svg+xml mime types

This allows users to link to SVG files hosted on github, where
the raw content is served up as plain text.
This commit is contained in:
Nyall Dawson 2018-03-29 08:45:17 +10:00
parent 50241dcba4
commit d3aae3f5b6

View File

@ -461,10 +461,13 @@ QByteArray QgsSvgCache::getImageData( const QString &path ) const
return mMissingSvg;
}
// we accept both real SVG mime types AND plain text types - because some sites
// (notably github) serve up svgs as raw text
QString contentType = reply->header( QNetworkRequest::ContentTypeHeader ).toString();
QgsDebugMsg( "contentType: " + contentType );
if ( !contentType.startsWith( QLatin1String( "image/svg+xml" ), Qt::CaseInsensitive ) )
if ( !contentType.startsWith( QLatin1String( "image/svg+xml" ), Qt::CaseInsensitive )
&& !contentType.startsWith( QLatin1String( "text/plain" ), Qt::CaseInsensitive ) )
{
QgsMessageLog::logMessage( tr( "Unexpected MIME type %1 received for %2" ).arg( contentType, path ), tr( "SVG" ) );
reply->deleteLater();
return mMissingSvg;
}