1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-17 22:38:33 +01:00

Support multiple headers in Cloudstream

This commit is contained in:
Uwe L. Korn 2014-06-10 16:30:59 +01:00
parent 705050aee8
commit 4ed2ff801d
3 changed files with 16 additions and 8 deletions

View File

@ -517,9 +517,17 @@ JSResolverHelper::nativeRetrieveMetadata( int metadataId, const QString& url,
if ( TomahawkUtils::isHttpResult( url ) || TomahawkUtils::isHttpsResult( url ) )
{
QMap<QString, QString> 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<TagLib::File> tag;

View File

@ -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<QString, QString>& 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());

View File

@ -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<QString, QString>& 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<QString, QString> headers_;
int cursor_;
QNetworkAccessManager* network_;