From f6254e9db6268f40cacce521ee2095e663740b2a Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 30 Jan 2012 19:39:14 +0200 Subject: [PATCH] Bug #919905: qBittorrent does not handle redirection to relative URLs correctly Thanks to luran for providing a first version of this patch. --- src/downloadthread.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/downloadthread.cpp b/src/downloadthread.cpp index bab1baa7d..ee355e3cc 100644 --- a/src/downloadthread.cpp +++ b/src/downloadthread.cpp @@ -66,9 +66,14 @@ void DownloadThread::processDlFinished(QNetworkReply* reply) { const QVariant redirection = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if(redirection.isValid()) { // We should redirect - qDebug("Redirecting from %s to %s", qPrintable(url), qPrintable(redirection.toUrl().toString())); - m_redirectMapping.insert(redirection.toUrl().toString(), url); - downloadUrl(redirection.toUrl().toString()); + QUrl newUrl = redirection.toUrl(); + // Resolve relative urls + if (newUrl.isRelative()) + newUrl = reply->url().resolved(newUrl); + const QString newUrlString = newUrl.toString(); + qDebug("Redirecting from %s to %s", qPrintable(url), qPrintable(newUrlString)); + m_redirectMapping.insert(newUrlString, url); + downloadUrl(newUrlString); reply->deleteLater(); return; }