mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-17 11:30:49 +02:00
Prevent redirect loops
This commit is contained in:
@@ -68,6 +68,7 @@ void
|
|||||||
NetworkReply::load( const QUrl& url )
|
NetworkReply::load( const QUrl& url )
|
||||||
{
|
{
|
||||||
m_url = url;
|
m_url = url;
|
||||||
|
m_formerUrls << url;
|
||||||
QNetworkRequest request( url );
|
QNetworkRequest request( url );
|
||||||
|
|
||||||
Q_ASSERT( Tomahawk::Utils::nam() != 0 );
|
Q_ASSERT( Tomahawk::Utils::nam() != 0 );
|
||||||
@@ -101,7 +102,7 @@ NetworkReply::networkLoadFinished()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVariant redir = m_reply->attribute( QNetworkRequest::RedirectionTargetAttribute );
|
QVariant redir = m_reply->attribute( QNetworkRequest::RedirectionTargetAttribute );
|
||||||
if ( redir.isValid() && !redir.toUrl().isEmpty() )
|
if ( redir.isValid() && !redir.toUrl().isEmpty() && m_formerUrls.count( redir.toUrl().toString() ) < maxSameRedirects && m_formerUrls.count() < maxRedirects )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Redirected HTTP request to" << redir;
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Redirected HTTP request to" << redir;
|
||||||
if ( m_blacklistedHosts.contains( redir.toUrl().host() ) )
|
if ( m_blacklistedHosts.contains( redir.toUrl().host() ) )
|
||||||
|
@@ -38,6 +38,9 @@ public:
|
|||||||
void blacklistHostFromRedirection( const QString& host );
|
void blacklistHostFromRedirection( const QString& host );
|
||||||
QNetworkReply* reply() const { return m_reply; }
|
QNetworkReply* reply() const { return m_reply; }
|
||||||
|
|
||||||
|
static const uint maxRedirects = 100;
|
||||||
|
static const uint maxSameRedirects = 5;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void redirected();
|
void redirected();
|
||||||
|
|
||||||
@@ -53,6 +56,7 @@ private:
|
|||||||
void load( const QUrl& url );
|
void load( const QUrl& url );
|
||||||
|
|
||||||
QStringList m_blacklistedHosts;
|
QStringList m_blacklistedHosts;
|
||||||
|
QStringList m_formerUrls;
|
||||||
QNetworkReply* m_reply;
|
QNetworkReply* m_reply;
|
||||||
QUrl m_url;
|
QUrl m_url;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user