NOISSUE Always follow redirects for NetAction based downloads
This commit is contained in:
@ -58,28 +58,25 @@ void ByteArrayDownload::downloadError(QNetworkReply::NetworkError error)
|
||||
|
||||
void ByteArrayDownload::downloadFinished()
|
||||
{
|
||||
if (m_followRedirects)
|
||||
QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
|
||||
QString redirectURL;
|
||||
if(redirect.isValid())
|
||||
{
|
||||
QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
|
||||
QString redirectURL;
|
||||
if(redirect.isValid())
|
||||
{
|
||||
redirectURL = redirect.toString();
|
||||
}
|
||||
// FIXME: This is a hack for https://bugreports.qt-project.org/browse/QTBUG-41061
|
||||
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());
|
||||
QLOG_INFO() << "Following redirect to " << m_url.toString();
|
||||
start();
|
||||
return;
|
||||
}
|
||||
redirectURL = redirect.toString();
|
||||
}
|
||||
// FIXME: This is a hack for https://bugreports.qt-project.org/browse/QTBUG-41061
|
||||
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());
|
||||
QLOG_INFO() << "Following redirect to " << m_url.toString();
|
||||
start();
|
||||
return;
|
||||
}
|
||||
|
||||
// if the download succeeded
|
||||
|
@ -33,8 +33,6 @@ public:
|
||||
|
||||
QString m_errorString;
|
||||
|
||||
bool m_followRedirects = false;
|
||||
|
||||
public
|
||||
slots:
|
||||
virtual void start();
|
||||
|
@ -101,28 +101,25 @@ void CacheDownload::downloadError(QNetworkReply::NetworkError error)
|
||||
}
|
||||
void CacheDownload::downloadFinished()
|
||||
{
|
||||
if (m_followRedirects)
|
||||
QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
|
||||
QString redirectURL;
|
||||
if(redirect.isValid())
|
||||
{
|
||||
QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
|
||||
QString redirectURL;
|
||||
if(redirect.isValid())
|
||||
{
|
||||
redirectURL = redirect.toString();
|
||||
}
|
||||
// FIXME: This is a hack for https://bugreports.qt-project.org/browse/QTBUG-41061
|
||||
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());
|
||||
QLOG_INFO() << "Following redirect to " << m_url.toString();
|
||||
start();
|
||||
return;
|
||||
}
|
||||
redirectURL = redirect.toString();
|
||||
}
|
||||
// FIXME: This is a hack for https://bugreports.qt-project.org/browse/QTBUG-41061
|
||||
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());
|
||||
QLOG_INFO() << "Following redirect to " << m_url.toString();
|
||||
start();
|
||||
return;
|
||||
}
|
||||
|
||||
// if the download succeeded
|
||||
|
@ -36,8 +36,6 @@ private:
|
||||
bool wroteAnyData = false;
|
||||
|
||||
public:
|
||||
bool m_followRedirects = false;
|
||||
|
||||
explicit CacheDownload(QUrl url, MetaEntryPtr entry);
|
||||
static CacheDownloadPtr make(QUrl url, MetaEntryPtr entry)
|
||||
{
|
||||
|
Reference in New Issue
Block a user