From 05fd0b5859bd6bfddcb8066066983ab3c34e1fa1 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Wed, 29 May 2019 15:50:02 +0300 Subject: [PATCH] Fix sequential downloading when redirected --- src/base/net/downloadmanager.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/base/net/downloadmanager.cpp b/src/base/net/downloadmanager.cpp index 12f2061f8..6f231e4a6 100644 --- a/src/base/net/downloadmanager.cpp +++ b/src/base/net/downloadmanager.cpp @@ -221,15 +221,15 @@ Net::DownloadHandler *Net::DownloadManager::download(const DownloadRequest &down m_waitingJobs[id].removeOne(downloadHandler); }); - if (!isSequentialService || !m_busyServices.contains(id)) { + if (isSequentialService && m_busyServices.contains(id)) { + m_waitingJobs[id].enqueue(downloadHandler); + } + else { qDebug("Downloading %s...", qUtf8Printable(downloadRequest.url())); if (isSequentialService) m_busyServices.insert(id); downloadHandler->assignNetworkReply(m_networkManager.get(request)); } - else { - m_waitingJobs[id].enqueue(downloadHandler); - } return downloadHandler; } @@ -308,9 +308,13 @@ void Net::DownloadManager::applyProxySettings() void Net::DownloadManager::handleReplyFinished(const QNetworkReply *reply) { - const ServiceID id = ServiceID::fromURL(reply->url()); + // QNetworkReply::url() may be different from that of the original request + // so we need QNetworkRequest::url() to properly process Sequential Services + // in the case when the redirection occurred. + const ServiceID id = ServiceID::fromURL(reply->request().url()); const auto waitingJobsIter = m_waitingJobs.find(id); if ((waitingJobsIter == m_waitingJobs.end()) || waitingJobsIter.value().isEmpty()) { + // No more waiting jobs for given ServiceID m_busyServices.remove(id); return; } @@ -437,13 +441,12 @@ namespace void DownloadHandlerImpl::processFinishedDownload() { - const QString url = m_reply->url().toString(); - qDebug("Download finished: %s", qUtf8Printable(url)); + qDebug("Download finished: %s", qUtf8Printable(url())); // Check if the request was successful if (m_reply->error() != QNetworkReply::NoError) { // Failure - qDebug("Download failure (%s), reason: %s", qUtf8Printable(url), qUtf8Printable(errorCodeToString(m_reply->error()))); + qDebug("Download failure (%s), reason: %s", qUtf8Printable(url()), qUtf8Printable(errorCodeToString(m_reply->error()))); setError(errorCodeToString(m_reply->error())); finish(); return;