summaryrefslogtreecommitdiffstats
path: root/api/logic/net/Download.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2018-01-21 03:49:54 +0100
committerPetr Mrázek <peterix@gmail.com>2018-01-21 03:49:54 +0100
commitc33b4e252f8bf37bc716adc7789926185c3e384c (patch)
treef37b58054385874f9dd079faa7809f19a21d5d1e /api/logic/net/Download.cpp
parent0942867ecc3d437cab8a859e2307c40b69d05297 (diff)
downloadMultiMC-c33b4e252f8bf37bc716adc7789926185c3e384c.tar
MultiMC-c33b4e252f8bf37bc716adc7789926185c3e384c.tar.gz
MultiMC-c33b4e252f8bf37bc716adc7789926185c3e384c.tar.lz
MultiMC-c33b4e252f8bf37bc716adc7789926185c3e384c.tar.xz
MultiMC-c33b4e252f8bf37bc716adc7789926185c3e384c.zip
NOISSUE fix bad redirect URLs provided by the curse CDN
MultiMC now parses the HTTP Location header in a (more) tolerant mode.
Diffstat (limited to 'api/logic/net/Download.cpp')
-rw-r--r--api/logic/net/Download.cpp42
1 files changed, 40 insertions, 2 deletions
diff --git a/api/logic/net/Download.cpp b/api/logic/net/Download.cpp
index 816d2002..e45c41cb 100644
--- a/api/logic/net/Download.cpp
+++ b/api/logic/net/Download.cpp
@@ -150,13 +150,50 @@ void Download::sslErrors(const QList<QSslError> & errors)
bool Download::handleRedirect()
{
- QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
+ QUrl redirect = m_reply->header(QNetworkRequest::LocationHeader).toUrl();
+ if(!redirect.isValid())
+ {
+ if(!m_reply->hasRawHeader("Location"))
+ {
+ // no redirect -> it's fine to continue
+ return false;
+ }
+ // there is a Location header, but it's not correct. we need to apply some workarounds...
+ QByteArray redirectBA = m_reply->rawHeader("Location");
+ if(redirectBA.size() == 0)
+ {
+ // empty, yet present redirect header? WTF?
+ return false;
+ }
+ QString redirectStr = QString::fromUtf8(redirectBA);
+
+ /*
+ * IF the URL begins with //, we need to insert the URL scheme.
+ * See: https://bugreports.qt-project.org/browse/QTBUG-41061
+ */
+ if(redirectStr.startsWith("//"))
+ {
+ redirectStr = m_reply->url().scheme() + ":" + redirectStr;
+ }
+
+ /*
+ * Next, make sure the URL is parsed in tolerant mode. Qt doesn't parse the location header in tolerant mode, which causes issues.
+ * FIXME: report Qt bug for this
+ */
+ redirect = QUrl(redirectStr, QUrl::TolerantMode);
+ qDebug() << "Fixed location header:" << redirect;
+ }
+ else
+ {
+ qDebug() << "Location header:" << redirect;
+ }
+
QString redirectURL;
if(redirect.isValid())
{
redirectURL = redirect.toString();
}
- // FIXME: This is a hack for https://bugreports.qt-project.org/browse/QTBUG-41061
+ // FIXME: This is a hack for
else if(m_reply->hasRawHeader("Location"))
{
auto data = m_reply->rawHeader("Location");
@@ -165,6 +202,7 @@ bool Download::handleRedirect()
redirectURL = m_reply->url().scheme() + ":" + data;
}
}
+
if (!redirectURL.isEmpty())
{
m_url = QUrl(redirect.toString());