mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 08:34:34 +02:00
Follow redirects on stream URL
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "network/Servent.h"
|
||||
#include "utils/Closure.h"
|
||||
#include "utils/NetworkAccessManager.h"
|
||||
#include "utils/NetworkReply.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include "config.h"
|
||||
@@ -595,9 +596,9 @@ void
|
||||
JSResolverHelper::returnStreamUrl( const QString& streamUrl, const QMap<QString, QString>& headers,
|
||||
boost::function< void( QSharedPointer< QIODevice >& ) > callback )
|
||||
{
|
||||
QSharedPointer< QIODevice > sp;
|
||||
if ( streamUrl.isEmpty() )
|
||||
{
|
||||
QSharedPointer< QIODevice > sp;
|
||||
callback( sp );
|
||||
return;
|
||||
}
|
||||
@@ -608,10 +609,21 @@ JSResolverHelper::returnStreamUrl( const QString& streamUrl, const QMap<QString,
|
||||
req.setRawHeader( key.toLatin1(), headers[key].toLatin1() );
|
||||
}
|
||||
tDebug() << "Creating a QNetowrkReply with url:" << req.url().toString();
|
||||
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
|
||||
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( req ) );
|
||||
|
||||
NewClosure( QSharedPointer<NetworkReply>( reply ) , SIGNAL( finalUrlReached ), this, SLOT( gotStreamUrl() ), callback );
|
||||
}
|
||||
|
||||
void
|
||||
JSResolverHelper::gotStreamUrl( boost::function< void( QSharedPointer< QIODevice >& ) > callback )
|
||||
{
|
||||
NetworkReply* reply = (NetworkReply*) sender();
|
||||
|
||||
//boost::functions cannot accept temporaries as parameters
|
||||
sp = QSharedPointer< QIODevice >( reply, &QObject::deleteLater );
|
||||
QSharedPointer< QIODevice > sp = QSharedPointer< QIODevice >( reply->reply(), &QObject::deleteLater );
|
||||
reply->disconnectFromReply();
|
||||
reply->deleteLater();
|
||||
|
||||
callback( sp );
|
||||
}
|
||||
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include <QVariantMap>
|
||||
|
||||
class JSResolver;
|
||||
Q_DECLARE_METATYPE( boost::function< void( QSharedPointer< QIODevice >& ) > )
|
||||
|
||||
class DLLEXPORT JSResolverHelper : public QObject
|
||||
{
|
||||
@@ -81,6 +82,7 @@ public slots:
|
||||
void reportCapabilities( const QVariant& capabilities );
|
||||
|
||||
private slots:
|
||||
void gotStreamUrl( boost::function< void( QSharedPointer< QIODevice >& ) > callback );
|
||||
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::ModelMode, const Tomahawk::collection_ptr& collection );
|
||||
void pltemplateTracksLoadedForUrl( const QString& url, const Tomahawk::playlisttemplate_ptr& pltemplate );
|
||||
|
||||
|
@@ -51,6 +51,14 @@ NetworkReply::blacklistHostFromRedirection( const QString& host )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NetworkReply::disconnectFromReply()
|
||||
{
|
||||
disconnectReplySignals();
|
||||
m_reply = NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NetworkReply::deletedByParent()
|
||||
{
|
||||
|
@@ -37,6 +37,7 @@ public:
|
||||
|
||||
void blacklistHostFromRedirection( const QString& host );
|
||||
QNetworkReply* reply() const { return m_reply; }
|
||||
void disconnectFromReply();
|
||||
|
||||
static const int maxRedirects = 100;
|
||||
static const int maxSameRedirects = 5;
|
||||
|
Reference in New Issue
Block a user