diff --git a/src/libtomahawk/utils/TomahawkUtils.cpp b/src/libtomahawk/utils/TomahawkUtils.cpp index 1f402b326..b7f5ffd7f 100644 --- a/src/libtomahawk/utils/TomahawkUtils.cpp +++ b/src/libtomahawk/utils/TomahawkUtils.cpp @@ -623,6 +623,27 @@ crash() } +const QString +operatingSystemVersionDetail() +{ +#ifdef Q_OS_LINUX + return QSettings( "/etc/os-release", QSettings::IniFormat ).value( "PRETTY_NAME", "Linux" ).toString(); +#else + return "Unknown"; +#endif +} + + +const QString +userAgentString( const QString& applicationName, const QString& applicationVersion ) +{ + return QString( "%1/%2 (%3)" ) + .arg( applicationName ) + .arg( applicationVersion ) + .arg( operatingSystemVersionDetail() ); +} + + void installTranslator( QObject* parent ) { diff --git a/src/libtomahawk/utils/TomahawkUtils.h b/src/libtomahawk/utils/TomahawkUtils.h index 00e14db8d..3dddd15e0 100644 --- a/src/libtomahawk/utils/TomahawkUtils.h +++ b/src/libtomahawk/utils/TomahawkUtils.h @@ -206,6 +206,11 @@ namespace TomahawkUtils DLLEXPORT void crash(); + /** + * User-Agent header helpers + */ + DLLEXPORT const QString operatingSystemVersionDetail(); + DLLEXPORT const QString userAgentString( const QString& applicationName, const QString& applicationVersion ); /** * Qt4 / Qt5 compatibility layer diff --git a/src/tomahawk/TomahawkApp.cpp b/src/tomahawk/TomahawkApp.cpp index 014701908..3adbba434 100644 --- a/src/tomahawk/TomahawkApp.cpp +++ b/src/tomahawk/TomahawkApp.cpp @@ -693,7 +693,13 @@ TomahawkApp::onInfoSystemReady() GlobalActionManager::instance(); // check if our spotify playlist api server is up and running, and enable spotify playlist drops if so - QNetworkReply* r = Tomahawk::Utils::nam()->get( QNetworkRequest( QUrl( SPOTIFY_PLAYLIST_API_URL "/pong" ) ) ); + QNetworkRequest request( QUrl( SPOTIFY_PLAYLIST_API_URL "/pong" ) ); + + QByteArray userAgent = TomahawkUtils::userAgentString( TOMAHAWK_APPLICATION_NAME, TOMAHAWK_VERSION ).toUtf8(); + tLog() << "User-Agent: " << userAgent; + request.setRawHeader( "User-Agent", userAgent ); + + QNetworkReply* r = Tomahawk::Utils::nam()->get( request ); connect( r, SIGNAL( finished() ), this, SLOT( spotifyApiCheckFinished() ) ); #ifdef Q_OS_MAC