1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 19:31:02 +01:00

Don't use Connection: Keep-Alive when doing requests to the Jamendo API

This commit is contained in:
David Sansome 2010-11-27 18:37:53 +00:00
parent 69d3d89b0f
commit 70df709fc2

View File

@ -1,7 +1,9 @@
#include "jamendodynamicplaylist.h" #include "jamendodynamicplaylist.h"
#include <QCoreApplication>
#include <QEventLoop> #include <QEventLoop>
#include <QNetworkReply> #include <QHttp>
#include <QHttpRequestHeader>
#include <QtDebug> #include <QtDebug>
#include "core/network.h" #include "core/network.h"
@ -89,25 +91,29 @@ void JamendoDynamicPlaylist::Fetch() {
url.addQueryItem("n", QString::number(kPageSize)); url.addQueryItem("n", QString::number(kPageSize));
url.addQueryItem("order", OrderSpec(order_by_, order_direction_)); url.addQueryItem("order", OrderSpec(order_by_, order_direction_));
// Have to make a new NetworkAccessManager here because we're in a different // We have to use QHttp here because there's no way to disable Keep-Alive
// thread. // with QNetworkManager.
NetworkAccessManager network; QHttpRequestHeader header("GET", url.encodedPath() + "?" + url.encodedQuery());
QNetworkRequest req(url); header.setValue("Host", url.encodedHost());
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::AlwaysNetwork);
QNetworkReply* reply = network.get(req); QHttp http(url.host());
http.request(header);
// Blocking wait for reply. // Wait for the reply
{ {
QEventLoop event_loop; QEventLoop event_loop;
connect(reply, SIGNAL(finished()), &event_loop, SLOT(quit())); connect(&http, SIGNAL(requestFinished(int,bool)), &event_loop, SLOT(quit()));
event_loop.exec(); event_loop.exec();
} }
if (http.error() != QHttp::NoError) {
qWarning() << "HTTP error returned from Jamendo:" << http.errorString()
<< ", url:" << url.toString();
return;
}
// The reply will contain one track ID per line // The reply will contain one track ID per line
QStringList lines = QString::fromAscii(reply->readAll()).split('\n'); QStringList lines = QString::fromAscii(http.readAll()).split('\n');
delete reply;
// Get the songs from the database // Get the songs from the database
SongList songs = backend_->GetSongsByForeignId( SongList songs = backend_->GetSongsByForeignId(