mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 09:43:07 -07:00
Allow to specify proxy option per request
This commit is contained in:
parent
8993d87b32
commit
4745a40f0b
15 changed files with 208 additions and 181 deletions
|
@ -56,16 +56,18 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
DownloadHandlerImpl::DownloadHandlerImpl(Net::DownloadManager *manager, const Net::DownloadRequest &downloadRequest)
|
||||
Net::DownloadHandlerImpl::DownloadHandlerImpl(DownloadManager *manager
|
||||
, const DownloadRequest &downloadRequest, const bool useProxy)
|
||||
: DownloadHandler {manager}
|
||||
, m_manager {manager}
|
||||
, m_downloadRequest {downloadRequest}
|
||||
, m_useProxy {useProxy}
|
||||
{
|
||||
m_result.url = url();
|
||||
m_result.status = Net::DownloadStatus::Success;
|
||||
m_result.status = DownloadStatus::Success;
|
||||
}
|
||||
|
||||
void DownloadHandlerImpl::cancel()
|
||||
void Net::DownloadHandlerImpl::cancel()
|
||||
{
|
||||
if (m_reply)
|
||||
{
|
||||
|
@ -78,7 +80,7 @@ void DownloadHandlerImpl::cancel()
|
|||
}
|
||||
}
|
||||
|
||||
void DownloadHandlerImpl::assignNetworkReply(QNetworkReply *reply)
|
||||
void Net::DownloadHandlerImpl::assignNetworkReply(QNetworkReply *reply)
|
||||
{
|
||||
Q_ASSERT(reply);
|
||||
Q_ASSERT(!m_reply);
|
||||
|
@ -91,17 +93,22 @@ void DownloadHandlerImpl::assignNetworkReply(QNetworkReply *reply)
|
|||
}
|
||||
|
||||
// Returns original url
|
||||
QString DownloadHandlerImpl::url() const
|
||||
QString Net::DownloadHandlerImpl::url() const
|
||||
{
|
||||
return m_downloadRequest.url();
|
||||
}
|
||||
|
||||
const Net::DownloadRequest DownloadHandlerImpl::downloadRequest() const
|
||||
Net::DownloadRequest Net::DownloadHandlerImpl::downloadRequest() const
|
||||
{
|
||||
return m_downloadRequest;
|
||||
}
|
||||
|
||||
void DownloadHandlerImpl::processFinishedDownload()
|
||||
bool Net::DownloadHandlerImpl::useProxy() const
|
||||
{
|
||||
return m_useProxy;
|
||||
}
|
||||
|
||||
void Net::DownloadHandlerImpl::processFinishedDownload()
|
||||
{
|
||||
qDebug("Download finished: %s", qUtf8Printable(url()));
|
||||
|
||||
|
@ -156,7 +163,7 @@ void DownloadHandlerImpl::processFinishedDownload()
|
|||
finish();
|
||||
}
|
||||
|
||||
void DownloadHandlerImpl::checkDownloadSize(const qint64 bytesReceived, const qint64 bytesTotal)
|
||||
void Net::DownloadHandlerImpl::checkDownloadSize(const qint64 bytesReceived, const qint64 bytesTotal)
|
||||
{
|
||||
if ((bytesTotal > 0) && (bytesTotal <= m_downloadRequest.limit()))
|
||||
{
|
||||
|
@ -175,7 +182,7 @@ void DownloadHandlerImpl::checkDownloadSize(const qint64 bytesReceived, const qi
|
|||
}
|
||||
}
|
||||
|
||||
void DownloadHandlerImpl::handleRedirection(const QUrl &newUrl)
|
||||
void Net::DownloadHandlerImpl::handleRedirection(const QUrl &newUrl)
|
||||
{
|
||||
if (m_redirectionCount >= MAX_REDIRECTIONS)
|
||||
{
|
||||
|
@ -202,9 +209,9 @@ void DownloadHandlerImpl::handleRedirection(const QUrl &newUrl)
|
|||
}
|
||||
|
||||
auto redirected = static_cast<DownloadHandlerImpl *>(
|
||||
m_manager->download(Net::DownloadRequest(m_downloadRequest).url(newUrlString)));
|
||||
m_manager->download(DownloadRequest(m_downloadRequest).url(newUrlString), useProxy()));
|
||||
redirected->m_redirectionCount = m_redirectionCount + 1;
|
||||
connect(redirected, &DownloadHandlerImpl::finished, this, [this](const Net::DownloadResult &result)
|
||||
connect(redirected, &DownloadHandlerImpl::finished, this, [this](const DownloadResult &result)
|
||||
{
|
||||
m_result = result;
|
||||
m_result.url = url();
|
||||
|
@ -212,18 +219,18 @@ void DownloadHandlerImpl::handleRedirection(const QUrl &newUrl)
|
|||
});
|
||||
}
|
||||
|
||||
void DownloadHandlerImpl::setError(const QString &error)
|
||||
void Net::DownloadHandlerImpl::setError(const QString &error)
|
||||
{
|
||||
m_result.errorString = error;
|
||||
m_result.status = Net::DownloadStatus::Failed;
|
||||
m_result.status = DownloadStatus::Failed;
|
||||
}
|
||||
|
||||
void DownloadHandlerImpl::finish()
|
||||
void Net::DownloadHandlerImpl::finish()
|
||||
{
|
||||
emit finished(m_result);
|
||||
}
|
||||
|
||||
QString DownloadHandlerImpl::errorCodeToString(const QNetworkReply::NetworkError status)
|
||||
QString Net::DownloadHandlerImpl::errorCodeToString(const QNetworkReply::NetworkError status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue