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

@ -92,7 +92,6 @@ set(SOURCES
core/musicstorage.cpp
core/network.cpp
core/networktimeouts.cpp
core/redirectfollower.cpp
core/networkproxyfactory.cpp
core/qtfslistener.cpp
core/settingsprovider.cpp
@ -301,7 +300,6 @@ set(HEADERS
core/mergedproxymodel.h
core/network.h
core/networktimeouts.h
core/redirectfollower.h
core/qtfslistener.h
core/songloader.h
core/tagreaderclient.h

View File

@ -123,6 +123,10 @@ QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkR
}
QNetworkRequest new_request(request);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
new_request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
new_request.setRawHeader("User-Agent", user_agent);
if (op == QNetworkAccessManager::PostOperation && !new_request.header(QNetworkRequest::ContentTypeHeader).isValid()) {

View File

@ -29,7 +29,6 @@
#include "core/closure.h"
#include "networktimeouts.h"
#include "redirectfollower.h"
NetworkTimeouts::NetworkTimeouts(int timeout_msec, QObject *parent)
: QObject(parent), timeout_msec_(timeout_msec) {}
@ -44,18 +43,6 @@ void NetworkTimeouts::AddReply(QNetworkReply *reply) {
}
void NetworkTimeouts::AddReply(RedirectFollower *reply) {
if (redirect_timers_.contains(reply)) {
return;
}
NewClosure(reply, SIGNAL(destroyed()), this, SLOT(RedirectFinished(RedirectFollower*)), reply);
NewClosure(reply, SIGNAL(finished()), this, SLOT(RedirectFinished(RedirectFollower*)), reply);
redirect_timers_[reply] = startTimer(timeout_msec_);
}
void NetworkTimeouts::ReplyFinished() {
QNetworkReply *reply = reinterpret_cast<QNetworkReply*>(sender());
@ -65,14 +52,6 @@ void NetworkTimeouts::ReplyFinished() {
}
void NetworkTimeouts::RedirectFinished(RedirectFollower *reply) {
if (redirect_timers_.contains(reply)) {
killTimer(redirect_timers_.take(reply));
}
}
void NetworkTimeouts::timerEvent(QTimerEvent *e) {
QNetworkReply *reply = timers_.key(e->timerId());
@ -80,11 +59,5 @@ void NetworkTimeouts::timerEvent(QTimerEvent *e) {
reply->abort();
}
RedirectFollower *redirect = redirect_timers_.key(e->timerId());
if (redirect) {
redirect->abort();
}
}

View File

@ -31,7 +31,6 @@
class QNetworkReply;
class QTimerEvent;
class RedirectFollower;
class NetworkTimeouts : public QObject {
Q_OBJECT
@ -39,9 +38,7 @@ class NetworkTimeouts : public QObject {
public:
explicit NetworkTimeouts(int timeout_msec, QObject *parent = nullptr);
// TODO: Template this to avoid code duplication.
void AddReply(QNetworkReply *reply);
void AddReply(RedirectFollower *reply);
void SetTimeout(int msec) { timeout_msec_ = msec; }
protected:
@ -49,12 +46,11 @@ class NetworkTimeouts : public QObject {
private slots:
void ReplyFinished();
void RedirectFinished(RedirectFollower *redirect);
private:
int timeout_msec_;
QMap<QNetworkReply*, int> timers_;
QMap<RedirectFollower*, int> redirect_timers_;
};
#endif // NETWORKTIMEOUTS_H

View File

@ -1,79 +0,0 @@
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QUrl>
#include <QNetworkRequest>
#include <QNetworkReply>
#include "redirectfollower.h"
RedirectFollower::RedirectFollower(QNetworkReply *first_reply, int max_redirects) : QObject(nullptr), current_reply_(first_reply), redirects_remaining_(max_redirects) {
ConnectReply(first_reply);
}
void RedirectFollower::ConnectReply(QNetworkReply *reply) {
connect(reply, SIGNAL(readyRead()), SLOT(ReadyRead()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SIGNAL(error(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(downloadProgress(qint64,qint64)));
connect(reply, SIGNAL(uploadProgress(qint64,qint64)), SIGNAL(uploadProgress(qint64,qint64)));
connect(reply, SIGNAL(finished()), SLOT(ReplyFinished()));
}
void RedirectFollower::ReadyRead() {
// Don't re-emit this signal for redirect replies.
if (current_reply_->attribute(QNetworkRequest::RedirectionTargetAttribute).isValid()) {
return;
}
emit readyRead();
}
void RedirectFollower::ReplyFinished() {
current_reply_->deleteLater();
if (current_reply_->attribute(QNetworkRequest::RedirectionTargetAttribute).isValid()) {
if (redirects_remaining_-- == 0) {
emit finished();
return;
}
const QUrl next_url = current_reply_->url().resolved(current_reply_->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl());
QNetworkRequest req(current_reply_->request());
req.setUrl(next_url);
current_reply_ = current_reply_->manager()->get(req);
ConnectReply(current_reply_);
return;
}
emit finished();
}

View File

@ -1,78 +0,0 @@
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef REDIRECTFOLLOWER_H
#define REDIRECTFOLLOWER_H
#include "config.h"
#include <stdbool.h>
#include <QtGlobal>
#include <QObject>
#include <QByteArray>
#include <QVariant>
#include <QString>
#include <QUrl>
#include <QNetworkRequest>
#include <QNetworkReply>
class RedirectFollower : public QObject {
Q_OBJECT
public:
explicit RedirectFollower(QNetworkReply *first_reply, int max_redirects = 5);
bool hit_redirect_limit() const { return redirects_remaining_ < 0; }
QNetworkReply *reply() const { return current_reply_; }
// These are all forwarded to the current reply.
QNetworkReply::NetworkError error() const { return current_reply_->error(); }
QString errorString() const { return current_reply_->errorString(); }
QVariant attribute(QNetworkRequest::Attribute code) const { return current_reply_->attribute(code); }
QVariant header(QNetworkRequest::KnownHeaders header) const { return current_reply_->header(header); }
qint64 bytesAvailable() const { return current_reply_->bytesAvailable(); }
QUrl url() const { return current_reply_->url(); }
QByteArray readAll() { return current_reply_->readAll(); }
void abort() { current_reply_->abort(); }
signals:
// These are all forwarded from the current reply.
void readyRead();
void error(QNetworkReply::NetworkError);
void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
// This is NOT emitted when a request that has a redirect finishes.
void finished();
private slots:
void ReadyRead();
void ReplyFinished();
private:
void ConnectReply(QNetworkReply *reply);
private:
QNetworkReply *current_reply_;
int redirects_remaining_;
};
#endif // REDIRECTFOLLOWER_H

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());

View File

@ -58,7 +58,11 @@ bool AuddLyricsProvider::StartSearch(const QString &artist, const QString &album
QUrl url(kUrlSearch);
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(HandleSearchReply(QNetworkReply*, const quint64, const QString&, const QString&)), reply, id, artist, title);
//qLog(Debug) << "AudDLyrics: Sending request for" << url;

View File

@ -53,7 +53,11 @@ bool LoloLyricsProvider::StartSearch(const QString &artist, const QString &album
QUrl url(kUrlSearch);
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(HandleSearchReply(QNetworkReply*, const quint64, const QString&, const QString&)), reply, id, artist, title);
//qLog(Debug) << "LoloLyrics: Sending request for" << url;

View File

@ -46,7 +46,11 @@ OVHLyricsProvider::OVHLyricsProvider(QObject *parent) : JsonLyricsProvider("Lyri
bool OVHLyricsProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) {
QUrl url(kUrlSearch + QString(QUrl::toPercentEncoding(artist)) + "/" + QString(QUrl::toPercentEncoding(title)));
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*, const quint64, const QString&, const QString&)), reply, id, artist, title);
//qLog(Debug) << "OVHLyrics: Sending request for" << url;

View File

@ -79,6 +79,9 @@ void AcoustidClient::Start(const int id, const QString &fingerprint, int duratio
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(RequestFinished(QNetworkReply*, int)), reply, id);
requests_[id] = reply;

View File

@ -157,6 +157,9 @@ void MusicBrainzClient::StartDiscIdRequest(const QString &discid) {
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(DiscIdRequestFinished(const QString&, QNetworkReply*)), discid, reply);
@ -178,6 +181,9 @@ void MusicBrainzClient::FlushRequests() {
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(RequestFinished(QNetworkReply*, const int, const int)), reply, request.id, request.number);
requests_.insert(request.id, reply);

View File

@ -66,6 +66,9 @@ QNetworkReply *QobuzBaseRequest::CreateRequest(const QString &ressource_name, co
url.setQuery(url_query);
QNetworkRequest req(url);
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
QNetworkReply *reply = network_->get(req);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(HandleSSLErrors(QList<QSslError>)));

View File

@ -21,16 +21,12 @@
#include <QObject>
#include <QPair>
#include <QList>
#include <QMultiMap>
#include <QByteArray>
#include <QString>
#include <QStringList>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonObject>
#include "core/logging.h"
#include "core/network.h"

View File

@ -22,7 +22,10 @@
#include "config.h"
#include <QObject>
#include <QList>
#include <QVariant>
#include <QString>
#include "qobuzbaserequest.h"
#include "core/song.h"

View File

@ -1125,6 +1125,9 @@ void QobuzRequest::FlushAlbumCoverRequests() {
++album_covers_requests_active_;
QNetworkRequest req(request.url);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
QNetworkReply *reply = network_->get(req);
album_cover_replies_ << reply;
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumCoverReceived(QNetworkReply*, const QUrl&, const QString&)), reply, request.url, request.filename);

View File

@ -105,6 +105,10 @@ QobuzService::QobuzService(Application *app, QObject *parent)
app->player()->RegisterUrlHandler(url_handler_);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
network_->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
#endif
// Backends
artists_collection_backend_ = new CollectionBackend();

View File

@ -180,6 +180,9 @@ void ListenBrainzScrobbler::RequestSession(QUrl url, QString token) {
url_query.addQueryItem("redirect_uri", url.toString());
QNetworkRequest req(session_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");
QByteArray query = url_query.toString(QUrl::FullyEncoded).toUtf8();
QNetworkReply *reply = network_->post(req, query);
@ -267,6 +270,9 @@ void ListenBrainzScrobbler::AuthenticateReplyFinished(QNetworkReply *reply) {
QNetworkReply *ListenBrainzScrobbler::CreateRequest(const QUrl &url, const QJsonDocument &json_doc) {
QNetworkRequest req(url);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
req.setRawHeader("Authorization", QString("Token %1").arg(user_token_).toUtf8());
QNetworkReply *reply = network_->post(req, json_doc.toJson());

View File

@ -207,6 +207,9 @@ void ScrobblingAPI20::RequestSession(QString token) {
session_url.setQuery(session_url_query);
QNetworkRequest req(session_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(AuthenticateReplyFinished(QNetworkReply*)), reply);
@ -334,6 +337,9 @@ QNetworkReply *ScrobblingAPI20::CreateRequest(const ParamList &request_params) {
QUrl url(api_url_);
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");
QByteArray query = url_query.toString(QUrl::FullyEncoded).toUtf8();
QNetworkReply *reply = network()->post(req, query);

View File

@ -64,6 +64,9 @@ QNetworkReply *TidalBaseRequest::CreateRequest(const QString &ressource_name, co
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 (!access_token().isEmpty()) req.setRawHeader("authorization", "Bearer " + access_token().toUtf8());
if (!session_id().isEmpty()) req.setRawHeader("X-Tidal-SessionId", session_id().toUtf8());

View File

@ -139,6 +139,9 @@ void TidalFavoriteRequest::AddFavorites(const FavoriteType type, const SongList
QUrl url(api_url() + QString("/") + "users/" + QString::number(service_->user_id()) + "/favorites/" + FavoriteText(type));
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 (!access_token().isEmpty()) req.setRawHeader("authorization", "Bearer " + access_token().toUtf8());
if (!session_id().isEmpty()) req.setRawHeader("X-Tidal-SessionId", session_id().toUtf8());
@ -242,6 +245,9 @@ void TidalFavoriteRequest::RemoveFavorites(const FavoriteType type, const int id
QUrl url(api_url() + QString("/") + "users/" + QString::number(service_->user_id()) + "/favorites/" + FavoriteText(type) + QString("/") + QString::number(id));
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 (!access_token().isEmpty()) req.setRawHeader("authorization", "Bearer " + access_token().toUtf8());
if (!session_id().isEmpty()) req.setRawHeader("X-Tidal-SessionId", session_id().toUtf8());

View File

@ -1067,6 +1067,9 @@ void TidalRequest::FlushAlbumCoverRequests() {
++album_covers_requests_active_;
QNetworkRequest req(request.url);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
QNetworkReply *reply = network_->get(req);
album_cover_replies_ << reply;
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumCoverReceived(QNetworkReply*, const QString&, const QUrl&, const QString&)), reply, request.album_id, request.url, request.filename);