Fix sequential downloading when redirected

This commit is contained in:
Vladimir Golovnev (Glassez) 2019-05-29 15:50:02 +03:00
parent c5430030e3
commit 05fd0b5859
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7

View file

@ -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;