Browse Source

Merge pull request #10723 from glassez/fix-seqdl

Fix sequential downloading when redirected
adaptive-webui-19844
Vladimir Golovnev 6 years ago committed by GitHub
parent
commit
c5768e3513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      src/base/net/downloadmanager.cpp

19
src/base/net/downloadmanager.cpp

@ -221,15 +221,15 @@ Net::DownloadHandler *Net::DownloadManager::download(const DownloadRequest &down
m_waitingJobs[id].removeOne(downloadHandler); 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())); qDebug("Downloading %s...", qUtf8Printable(downloadRequest.url()));
if (isSequentialService) if (isSequentialService)
m_busyServices.insert(id); m_busyServices.insert(id);
downloadHandler->assignNetworkReply(m_networkManager.get(request)); downloadHandler->assignNetworkReply(m_networkManager.get(request));
} }
else {
m_waitingJobs[id].enqueue(downloadHandler);
}
return downloadHandler; return downloadHandler;
} }
@ -308,9 +308,13 @@ void Net::DownloadManager::applyProxySettings()
void Net::DownloadManager::handleReplyFinished(const QNetworkReply *reply) 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); const auto waitingJobsIter = m_waitingJobs.find(id);
if ((waitingJobsIter == m_waitingJobs.end()) || waitingJobsIter.value().isEmpty()) { if ((waitingJobsIter == m_waitingJobs.end()) || waitingJobsIter.value().isEmpty()) {
// No more waiting jobs for given ServiceID
m_busyServices.remove(id); m_busyServices.remove(id);
return; return;
} }
@ -437,13 +441,12 @@ namespace
void DownloadHandlerImpl::processFinishedDownload() 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 // Check if the request was successful
if (m_reply->error() != QNetworkReply::NoError) { if (m_reply->error() != QNetworkReply::NoError) {
// Failure // 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())); setError(errorCodeToString(m_reply->error()));
finish(); finish();
return; return;

Loading…
Cancel
Save