diff --git a/src/libtomahawk/resolvers/JSResolverHelper.cpp b/src/libtomahawk/resolvers/JSResolverHelper.cpp index af2bceb16..11f180055 100644 --- a/src/libtomahawk/resolvers/JSResolverHelper.cpp +++ b/src/libtomahawk/resolvers/JSResolverHelper.cpp @@ -517,9 +517,17 @@ JSResolverHelper::nativeRetrieveMetadata( int metadataId, const QString& url, if ( TomahawkUtils::isHttpResult( url ) || TomahawkUtils::isHttpsResult( url ) ) { + QMap headers; + if ( options.contains( "headers" ) && options["headers"].canConvert( QVariant::Map ) ) + { + const QVariantMap variantHeaders = options["headers"].toMap(); + foreach ( const QString& key, variantHeaders.keys() ) { + headers.insert( key, variantHeaders[key].toString() ); + } + } + // TODO: Add heuristic if size is not defined - // TOOD: Support pushing multiple headers - CloudStream stream( url, sizehint, QString("insert headers here"), + CloudStream stream( url, sizehint, headers, Tomahawk::Utils::nam() ); stream.Precache(); QScopedPointer tag; diff --git a/src/libtomahawk/utils/Cloudstream.cpp b/src/libtomahawk/utils/Cloudstream.cpp index 065939d92..0e2801dce 100644 --- a/src/libtomahawk/utils/Cloudstream.cpp +++ b/src/libtomahawk/utils/Cloudstream.cpp @@ -33,12 +33,12 @@ static const int kTaglibSuffixCacheBytes = 8 * 1024; } CloudStream::CloudStream(const QUrl& url, - const long length, const QString& auth, + const long length, const QMap& headers, QNetworkAccessManager* network) : url_(url), encoded_filename_(url.fileName().toUtf8()), length_(length), - auth_(auth), + headers_(headers), cursor_(0), network_(network), cache_(length), @@ -106,8 +106,8 @@ TagLib::ByteVector CloudStream::readBlock(ulong length) { } QNetworkRequest request = QNetworkRequest(url_); - if (!auth_.isEmpty()) { - request.setRawHeader("Authorization", auth_.toUtf8()); + foreach (const QString& key, headers_) { + request.setRawHeader(key.toLatin1(), headers_[key].toUtf8()); } request.setRawHeader("Range", QString("bytes=%1-%2").arg(start).arg(end).toUtf8()); diff --git a/src/libtomahawk/utils/Cloudstream.h b/src/libtomahawk/utils/Cloudstream.h index 26cdf784b..8ff62b717 100644 --- a/src/libtomahawk/utils/Cloudstream.h +++ b/src/libtomahawk/utils/Cloudstream.h @@ -32,7 +32,7 @@ class CloudStream : public QObject, public TagLib::IOStream { Q_OBJECT public: CloudStream(const QUrl& url, const long length, - const QString& auth, QNetworkAccessManager* network); + const QMap& headers, QNetworkAccessManager* network); // Taglib::IOStream virtual TagLib::FileName name() const; @@ -70,7 +70,7 @@ class CloudStream : public QObject, public TagLib::IOStream { const QString filename_; const QByteArray encoded_filename_; const ulong length_; - const QString auth_; + const QMap headers_; int cursor_; QNetworkAccessManager* network_;