NOISSUE clean up download redirects and handle their errors as fatal

This commit is contained in:
Petr Mrázek 2018-01-22 03:09:00 +01:00
parent c33b4e252f
commit 0c2e2094ee

View File

@ -181,6 +181,12 @@ bool Download::handleRedirect()
* FIXME: report Qt bug for this * FIXME: report Qt bug for this
*/ */
redirect = QUrl(redirectStr, QUrl::TolerantMode); redirect = QUrl(redirectStr, QUrl::TolerantMode);
if(!redirect.isValid())
{
qWarning() << "Failed to parse redirect URL:" << redirectStr;
downloadError(QNetworkReply::ProtocolFailure);
return false;
}
qDebug() << "Fixed location header:" << redirect; qDebug() << "Fixed location header:" << redirect;
} }
else else
@ -188,30 +194,11 @@ bool Download::handleRedirect()
qDebug() << "Location header:" << redirect; qDebug() << "Location header:" << redirect;
} }
QString redirectURL;
if(redirect.isValid())
{
redirectURL = redirect.toString();
}
// FIXME: This is a hack for
else if(m_reply->hasRawHeader("Location"))
{
auto data = m_reply->rawHeader("Location");
if(data.size() > 2 && data[0] == '/' && data[1] == '/')
{
redirectURL = m_reply->url().scheme() + ":" + data;
}
}
if (!redirectURL.isEmpty())
{
m_url = QUrl(redirect.toString()); m_url = QUrl(redirect.toString());
qDebug() << "Following redirect to " << m_url.toString(); qDebug() << "Following redirect to " << m_url.toString();
start(); start();
return true; return true;
} }
return false;
}
void Download::downloadFinished() void Download::downloadFinished()