Use FollowRedirectsAttribute everywhere

This commit is contained in:
Jonas Kvinge
2019-08-22 19:28:54 +02:00
parent 387d790228
commit bd5ab80276
28 changed files with 102 additions and 212 deletions

View File

@@ -39,7 +39,6 @@
#include "core/logging.h"
#include "core/network.h"
#include "core/networktimeouts.h"
#include "core/redirectfollower.h"
#include "albumcoverfetcher.h"
#include "albumcoverfetchersearch.h"
#include "coverprovider.h"
@@ -183,12 +182,16 @@ void AlbumCoverFetcherSearch::FetchMoreImages() {
qLog(Debug) << "Loading" << result.image_url << "from" << result.provider;
RedirectFollower *image_reply = new RedirectFollower(network_->get(QNetworkRequest(result.image_url)));
NewClosure(image_reply, SIGNAL(finished()), this, SLOT(ProviderCoverFetchFinished(RedirectFollower*)), image_reply);
QNetworkRequest req(result.image_url);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
QNetworkReply *image_reply = network_->get(req);
NewClosure(image_reply, SIGNAL(finished()), this, SLOT(ProviderCoverFetchFinished(QNetworkReply*)), image_reply);
pending_image_loads_[image_reply] = result;
image_load_timeout_->AddReply(image_reply);
statistics_.network_requests_made_++;
++statistics_.network_requests_made_;
}
if (pending_image_loads_.isEmpty()) {
@@ -198,7 +201,7 @@ void AlbumCoverFetcherSearch::FetchMoreImages() {
}
void AlbumCoverFetcherSearch::ProviderCoverFetchFinished(RedirectFollower *reply) {
void AlbumCoverFetcherSearch::ProviderCoverFetchFinished(QNetworkReply *reply) {
reply->deleteLater();
@@ -298,7 +301,7 @@ void AlbumCoverFetcherSearch::Cancel() {
TerminateSearch();
}
else if (!pending_image_loads_.isEmpty()) {
for (RedirectFollower *reply : pending_image_loads_.keys()) {
for (QNetworkReply *reply : pending_image_loads_.keys()) {
reply->abort();
}
pending_image_loads_.clear();

View File

@@ -37,10 +37,10 @@
#include "albumcoverfetcher.h"
#include "coversearchstatistics.h"
class QNetworkReply;
class CoverProvider;
class CoverProviders;
class NetworkTimeouts;
class RedirectFollower;
// This class encapsulates a single search for covers initiated by an AlbumCoverFetcher.
// The search engages all of the known cover providers.
@@ -67,7 +67,7 @@ class AlbumCoverFetcherSearch : public QObject {
private slots:
void ProviderSearchFinished(const int id, const CoverSearchResults &results);
void ProviderCoverFetchFinished(RedirectFollower *reply);
void ProviderCoverFetchFinished(QNetworkReply *reply);
void TerminateSearch();
private:
@@ -92,7 +92,7 @@ class AlbumCoverFetcherSearch : public QObject {
CoverSearchResults results_;
QMap<int, CoverProvider*> pending_requests_;
QMap<RedirectFollower*, CoverSearchResult> pending_image_loads_;
QMap<QNetworkReply*, CoverSearchResult> pending_image_loads_;
NetworkTimeouts* image_load_timeout_;
// QMap is sorted by key (score). Values are (result, image)

View File

@@ -69,6 +69,9 @@ bool DeezerCoverProvider::StartSearch(const QString &artist, const QString &albu
QUrl url(kApiUrl + QString("/search/album"));
url.setQuery(url_query);
QNetworkRequest req(url);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
QNetworkReply *reply = network_->get(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, int)), reply, id);

View File

@@ -132,7 +132,11 @@ void DiscogsCoverProvider::SendSearchRequest(DiscogsCoverSearchContext *s_ctx) {
// Add the signature to the request
url_query.addQueryItem("Signature", QUrl::toPercentEncoding(signature.toBase64()));
QNetworkReply *reply = network_->get(QNetworkRequest(url));
QNetworkRequest req(url);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
QNetworkReply *reply = network_->get(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, int)), reply, s_ctx->id);
}
@@ -167,7 +171,11 @@ void DiscogsCoverProvider::SendReleaseRequest(DiscogsCoverSearchContext *s_ctx,
url.setQuery(url_query);
QNetworkReply *reply = network_->get(QNetworkRequest(url));
QNetworkRequest req(url);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
QNetworkReply *reply = network_->get(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleReleaseReply(QNetworkReply*, int, int)), reply, s_ctx->id, r_ctx->id);
}

View File

@@ -79,6 +79,9 @@ bool LastFmCoverProvider::StartSearch(const QString &artist, const QString &albu
QUrl url(kUrl);
QNetworkRequest req(url);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QNetworkReply *reply = network_->post(req, url_query.toString(QUrl::FullyEncoded).toUtf8());
NewClosure(reply, SIGNAL(finished()), this, SLOT(QueryFinished(QNetworkReply*, int)), reply, id);

View File

@@ -62,9 +62,11 @@ bool MusicbrainzCoverProvider::StartSearch(const QString &artist, const QString
QUrl url(kReleaseSearchUrl);
url.setQuery(url_query);
QNetworkRequest request(url);
QNetworkReply *reply = network_->get(request);
QNetworkRequest req(url);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
QNetworkReply *reply = network_->get(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply *, int)), reply, id);
return true;

View File

@@ -87,6 +87,9 @@ QNetworkReply *TidalCoverProvider::CreateRequest(const QString &ressource_name,
QUrl url(kApiUrl + QString("/") + ressource_name);
url.setQuery(url_query);
QNetworkRequest req(url);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
if (!service_->access_token().isEmpty()) req.setRawHeader("authorization", "Bearer " + service_->access_token().toUtf8());
if (!service_->session_id().isEmpty()) req.setRawHeader("X-Tidal-SessionId", service_->session_id().toUtf8());