1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-21 08:21:54 +02:00

Merge pull request #316 from theli-ua/user_agent

Add ability for resolvers to specify user agent string
This commit is contained in:
Dominik Schmidt 2015-09-01 22:44:47 +02:00
commit ad1c9ff847
3 changed files with 16 additions and 3 deletions

View File

@ -431,7 +431,7 @@ Tomahawk.nativeAsyncRequestDone = function (reqId, xhr) {
if (Tomahawk.asyncRequestCallbacks[reqId].callback) {
Tomahawk.asyncRequestCallbacks[reqId].callback(xhr);
}
} else if (xmlHttpRequest.readyState === 4) {
} else if (xhr.readyState === 4) {
Tomahawk.log("Failed to do nativeAsyncRequest");
Tomahawk.log("Status Code was: " + xhr.status);
if (Tomahawk.asyncRequestCallbacks[reqId].errorHandler) {
@ -500,7 +500,8 @@ Tomahawk.asyncRequest = function (url, callback, extraHeaders, options) {
*/
var shouldDoNativeRequest = function (url, callback, extraHeaders, options) {
return (extraHeaders && (extraHeaders.hasOwnProperty("Referer")
|| extraHeaders.hasOwnProperty("referer")));
|| extraHeaders.hasOwnProperty("referer")
|| extraHeaders.hasOwnProperty("User-Agent")));
};
Tomahawk.ajax = function(url, settings) {
@ -563,8 +564,12 @@ Tomahawk.ajax = function(url, settings) {
contentType = 'application/json';
} else if (contentType === 'xml') {
contentType = 'text/xml';
} else {
} else if (typeof xhr.getResponseHeader !== 'undefined') {
contentType = xhr.getResponseHeader('Content-Type');
} else if (xhr.hasOwnProperty('contentType')) {
contentType = xhr['contentType'];
} else {
contentType = 'text/html';
}
if (~contentType.indexOf('application/json')) {

View File

@ -951,6 +951,8 @@ JSResolverHelper::nativeAsyncRequestDone( int requestId, NetworkReply* reply )
map["status"] = reply->reply()->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
map["statusText"] = QString("%1 %2").arg( map["status"].toString() )
.arg( reply->reply()->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString() );
if (reply->reply()->hasRawHeader( "Content-Type" ))
map["contentType"] = reply->reply()->rawHeader( "Content-Type" );
bool ok = false;
QString json = QString::fromUtf8( TomahawkUtils::toJson( map, &ok ) );

View File

@ -148,6 +148,12 @@ NetworkReply::load( const QUrl& url )
m_formerUrls << url.toString();
QNetworkRequest request( url );
//Carryover User-Agent
if ( m_reply->request().hasRawHeader( "User-Agent" ))
{
request.setRawHeader( "User-Agent", m_reply->request().rawHeader( "User-Agent" ) );
}
Q_ASSERT( Tomahawk::Utils::nam() != 0 );
QNetworkAccessManager::Operation op = m_reply->operation();