mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-13 07:42:26 +03:00
parent
409557ef30
commit
8fe1ff87f1
2 changed files with 11 additions and 1 deletions
|
@ -44,6 +44,8 @@
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
const int MAX_REDIRECTIONS = 20; // the common value for web browsers
|
||||||
|
|
||||||
bool saveToFile(const QByteArray &replyData, QString &filePath)
|
bool saveToFile(const QByteArray &replyData, QString &filePath)
|
||||||
{
|
{
|
||||||
QTemporaryFile tmpfile {Utils::Fs::tempPath() + "XXXXXX"};
|
QTemporaryFile tmpfile {Utils::Fs::tempPath() + "XXXXXX"};
|
||||||
|
@ -155,6 +157,12 @@ void Net::DownloadHandler::checkDownloadSize(qint64 bytesReceived, qint64 bytesT
|
||||||
|
|
||||||
void Net::DownloadHandler::handleRedirection(const QUrl &newUrl)
|
void Net::DownloadHandler::handleRedirection(const QUrl &newUrl)
|
||||||
{
|
{
|
||||||
|
if (m_redirectionCounter >= MAX_REDIRECTIONS) {
|
||||||
|
emit downloadFailed(url(), tr("Exceeded max redirections (%1)").arg(MAX_REDIRECTIONS));
|
||||||
|
this->deleteLater();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve relative urls
|
// Resolve relative urls
|
||||||
const QUrl resolvedUrl = (newUrl.isRelative()) ? m_reply->url().resolved(newUrl) : newUrl;
|
const QUrl resolvedUrl = (newUrl.isRelative()) ? m_reply->url().resolved(newUrl) : newUrl;
|
||||||
const QString newUrlString = resolvedUrl.toString();
|
const QString newUrlString = resolvedUrl.toString();
|
||||||
|
@ -173,7 +181,8 @@ void Net::DownloadHandler::handleRedirection(const QUrl &newUrl)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DownloadHandler *redirected = m_manager->download(DownloadRequest(m_downloadRequest).url(newUrlString));
|
DownloadHandler *redirected = m_manager->download(DownloadRequest(m_downloadRequest).url(newUrlString));
|
||||||
|
redirected->m_redirectionCounter = (m_redirectionCounter + 1);
|
||||||
connect(redirected, &DownloadHandler::destroyed, this, &DownloadHandler::deleteLater);
|
connect(redirected, &DownloadHandler::destroyed, this, &DownloadHandler::deleteLater);
|
||||||
connect(redirected, &DownloadHandler::downloadFailed, this, [this](const QString &, const QString &reason)
|
connect(redirected, &DownloadHandler::downloadFailed, this, [this](const QString &, const QString &reason)
|
||||||
{
|
{
|
||||||
|
|
|
@ -74,6 +74,7 @@ namespace Net
|
||||||
QNetworkReply *m_reply;
|
QNetworkReply *m_reply;
|
||||||
DownloadManager *m_manager;
|
DownloadManager *m_manager;
|
||||||
const DownloadRequest m_downloadRequest;
|
const DownloadRequest m_downloadRequest;
|
||||||
|
short m_redirectionCounter = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue