mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +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:
@@ -431,7 +431,7 @@ Tomahawk.nativeAsyncRequestDone = function (reqId, xhr) {
|
|||||||
if (Tomahawk.asyncRequestCallbacks[reqId].callback) {
|
if (Tomahawk.asyncRequestCallbacks[reqId].callback) {
|
||||||
Tomahawk.asyncRequestCallbacks[reqId].callback(xhr);
|
Tomahawk.asyncRequestCallbacks[reqId].callback(xhr);
|
||||||
}
|
}
|
||||||
} else if (xmlHttpRequest.readyState === 4) {
|
} else if (xhr.readyState === 4) {
|
||||||
Tomahawk.log("Failed to do nativeAsyncRequest");
|
Tomahawk.log("Failed to do nativeAsyncRequest");
|
||||||
Tomahawk.log("Status Code was: " + xhr.status);
|
Tomahawk.log("Status Code was: " + xhr.status);
|
||||||
if (Tomahawk.asyncRequestCallbacks[reqId].errorHandler) {
|
if (Tomahawk.asyncRequestCallbacks[reqId].errorHandler) {
|
||||||
@@ -500,7 +500,8 @@ Tomahawk.asyncRequest = function (url, callback, extraHeaders, options) {
|
|||||||
*/
|
*/
|
||||||
var shouldDoNativeRequest = function (url, callback, extraHeaders, options) {
|
var shouldDoNativeRequest = function (url, callback, extraHeaders, options) {
|
||||||
return (extraHeaders && (extraHeaders.hasOwnProperty("Referer")
|
return (extraHeaders && (extraHeaders.hasOwnProperty("Referer")
|
||||||
|| extraHeaders.hasOwnProperty("referer")));
|
|| extraHeaders.hasOwnProperty("referer")
|
||||||
|
|| extraHeaders.hasOwnProperty("User-Agent")));
|
||||||
};
|
};
|
||||||
|
|
||||||
Tomahawk.ajax = function(url, settings) {
|
Tomahawk.ajax = function(url, settings) {
|
||||||
@@ -563,8 +564,12 @@ Tomahawk.ajax = function(url, settings) {
|
|||||||
contentType = 'application/json';
|
contentType = 'application/json';
|
||||||
} else if (contentType === 'xml') {
|
} else if (contentType === 'xml') {
|
||||||
contentType = 'text/xml';
|
contentType = 'text/xml';
|
||||||
} else {
|
} else if (typeof xhr.getResponseHeader !== 'undefined') {
|
||||||
contentType = xhr.getResponseHeader('Content-Type');
|
contentType = xhr.getResponseHeader('Content-Type');
|
||||||
|
} else if (xhr.hasOwnProperty('contentType')) {
|
||||||
|
contentType = xhr['contentType'];
|
||||||
|
} else {
|
||||||
|
contentType = 'text/html';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (~contentType.indexOf('application/json')) {
|
if (~contentType.indexOf('application/json')) {
|
||||||
|
@@ -951,6 +951,8 @@ JSResolverHelper::nativeAsyncRequestDone( int requestId, NetworkReply* reply )
|
|||||||
map["status"] = reply->reply()->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
|
map["status"] = reply->reply()->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
|
||||||
map["statusText"] = QString("%1 %2").arg( map["status"].toString() )
|
map["statusText"] = QString("%1 %2").arg( map["status"].toString() )
|
||||||
.arg( reply->reply()->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString() );
|
.arg( reply->reply()->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString() );
|
||||||
|
if (reply->reply()->hasRawHeader( "Content-Type" ))
|
||||||
|
map["contentType"] = reply->reply()->rawHeader( "Content-Type" );
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
QString json = QString::fromUtf8( TomahawkUtils::toJson( map, &ok ) );
|
QString json = QString::fromUtf8( TomahawkUtils::toJson( map, &ok ) );
|
||||||
|
@@ -148,6 +148,12 @@ NetworkReply::load( const QUrl& url )
|
|||||||
m_formerUrls << url.toString();
|
m_formerUrls << url.toString();
|
||||||
QNetworkRequest request( url );
|
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 );
|
Q_ASSERT( Tomahawk::Utils::nam() != 0 );
|
||||||
|
|
||||||
QNetworkAccessManager::Operation op = m_reply->operation();
|
QNetworkAccessManager::Operation op = m_reply->operation();
|
||||||
|
Reference in New Issue
Block a user