2012-02-29 18:33:50 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-10-29 13:36:04 +02:00
|
|
|
#include "followredirectreply.h"
|
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
|
2011-10-29 13:36:04 +02:00
|
|
|
FollowRedirectReply::FollowRedirectReply(const QUrl &url, QNetworkAccessManager* manager)
|
|
|
|
: QObject()
|
|
|
|
, m_manager(manager)
|
|
|
|
, m_redirectCount(0)
|
|
|
|
{
|
|
|
|
m_reply = m_manager->get(QNetworkRequest(url));
|
|
|
|
connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
|
|
|
|
}
|
|
|
|
|
2012-07-03 21:54:04 +02:00
|
|
|
QNetworkReply* FollowRedirectReply::reply() const
|
|
|
|
{
|
|
|
|
return m_reply;
|
|
|
|
}
|
|
|
|
|
2012-07-08 00:15:03 +02:00
|
|
|
QUrl FollowRedirectReply::originalUrl() const
|
|
|
|
{
|
|
|
|
return m_reply->request().url();
|
|
|
|
}
|
|
|
|
|
2012-07-03 21:54:04 +02:00
|
|
|
QUrl FollowRedirectReply::url() const
|
|
|
|
{
|
|
|
|
return m_reply->url();
|
|
|
|
}
|
|
|
|
|
|
|
|
QNetworkReply::NetworkError FollowRedirectReply::error() const
|
|
|
|
{
|
|
|
|
return m_reply->error();
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray FollowRedirectReply::readAll()
|
|
|
|
{
|
|
|
|
return m_reply->readAll();
|
|
|
|
}
|
|
|
|
|
2011-10-29 13:36:04 +02:00
|
|
|
void FollowRedirectReply::replyFinished()
|
|
|
|
{
|
|
|
|
int replyStatus = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if ((replyStatus != 301 && replyStatus != 302) || m_redirectCount == 5) {
|
2011-10-29 13:36:04 +02:00
|
|
|
emit finished();
|
|
|
|
return;
|
|
|
|
}
|
2012-07-03 21:54:04 +02:00
|
|
|
|
2011-10-29 13:36:04 +02:00
|
|
|
m_redirectCount++;
|
|
|
|
|
|
|
|
QUrl redirectUrl = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
|
|
|
|
m_reply->close();
|
|
|
|
m_reply->deleteLater();
|
|
|
|
|
|
|
|
m_reply = m_manager->get(QNetworkRequest(redirectUrl));
|
|
|
|
connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
|
|
|
|
}
|
|
|
|
|
|
|
|
FollowRedirectReply::~FollowRedirectReply()
|
|
|
|
{
|
|
|
|
m_reply->close();
|
|
|
|
m_reply->deleteLater();
|
|
|
|
}
|