mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-19 12:22:47 +01:00
fixed #443
This commit is contained in:
parent
6e51dd34b0
commit
868d75b182
@ -30,7 +30,7 @@
|
||||
<url type="donation">https://martinrotter.github.io/donate/</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="3.9.2" date="2021-06-25"/>
|
||||
<release version="3.9.2" date="2021-06-28"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -32,13 +32,6 @@ void BaseNetworkAccessManager::loadSettings() {
|
||||
qDebugNN << LOGSEC_NETWORK << "Settings of BaseNetworkAccessManager loaded.";
|
||||
}
|
||||
|
||||
void BaseNetworkAccessManager::acceptRedirection(const QUrl& url) {
|
||||
auto* reply = qobject_cast<QNetworkReply*>(sender());
|
||||
emit reply->redirectAllowed();
|
||||
|
||||
qDebugNN << LOGSEC_NETWORK << "Accepting redirect to" << QUOTE_W_SPACE_DOT(url.toString());
|
||||
}
|
||||
|
||||
void BaseNetworkAccessManager::onSslErrors(QNetworkReply* reply, const QList<QSslError>& error) {
|
||||
qWarningNN << LOGSEC_NETWORK
|
||||
<< "Ignoring SSL errors for"
|
||||
@ -60,17 +53,9 @@ QNetworkReply* BaseNetworkAccessManager::createRequest(QNetworkAccessManager::Op
|
||||
new_request.setAttribute(QNetworkRequest::Attribute::Http2AllowedAttribute, true);
|
||||
#endif
|
||||
|
||||
#if QT_VERSION >= 0x050900 // Qt >= 5.9.0
|
||||
new_request.setAttribute(QNetworkRequest::Attribute::RedirectPolicyAttribute,
|
||||
QNetworkRequest::RedirectPolicy::UserVerifiedRedirectPolicy);
|
||||
#elif QT_VERSION >= 0x050600 // Qt >= 5.6.0
|
||||
new_request.setAttribute(QNetworkRequest::Attribute::FollowRedirectsAttribute, true);
|
||||
#endif
|
||||
|
||||
new_request.setRawHeader(HTTP_HEADERS_COOKIE, QSL("JSESSIONID= ").toLocal8Bit());
|
||||
new_request.setRawHeader(HTTP_HEADERS_USER_AGENT, QString(APP_USERAGENT).toLocal8Bit());
|
||||
|
||||
auto reply = QNetworkAccessManager::createRequest(op, new_request, outgoingData);
|
||||
connect(reply, &QNetworkReply::redirected, this, &BaseNetworkAccessManager::acceptRedirection);
|
||||
return reply;
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ class BaseNetworkAccessManager : public QNetworkAccessManager {
|
||||
void loadSettings();
|
||||
|
||||
protected slots:
|
||||
void acceptRedirection(const QUrl& url);
|
||||
void onSslErrors(QNetworkReply* reply, const QList<QSslError>& error);
|
||||
|
||||
protected:
|
||||
|
@ -118,25 +118,77 @@ void Downloader::manipulateData(const QString& url,
|
||||
void Downloader::finished() {
|
||||
auto* reply = qobject_cast<QNetworkReply*>(sender());
|
||||
|
||||
QNetworkAccessManager::Operation reply_operation = reply->operation();
|
||||
|
||||
m_timer->stop();
|
||||
|
||||
if (m_inputMultipartData == nullptr) {
|
||||
m_lastOutputData = reply->readAll();
|
||||
// In this phase, some part of downloading process is completed.
|
||||
QUrl redirection_url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
|
||||
|
||||
if (redirection_url.isValid()) {
|
||||
// Communication indicates that HTTP redirection is needed.
|
||||
// Setup redirection URL and download again.
|
||||
QNetworkRequest request = reply->request();
|
||||
|
||||
qWarningNN << LOGSEC_NETWORK
|
||||
<< "Network layer indicates HTTP redirection is needed.";
|
||||
qWarningNN << LOGSEC_NETWORK
|
||||
<< "Origin URL:"
|
||||
<< QUOTE_W_SPACE_DOT(request.url().toString());
|
||||
qWarningNN << LOGSEC_NETWORK
|
||||
<< "Proposed redirection URL:"
|
||||
<< QUOTE_W_SPACE_DOT(redirection_url.toString());
|
||||
|
||||
redirection_url = request.url().resolved(redirection_url);
|
||||
|
||||
qWarningNN << LOGSEC_NETWORK
|
||||
<< "Resolved redirection URL:"
|
||||
<< QUOTE_W_SPACE_DOT(redirection_url.toString());
|
||||
|
||||
request.setUrl(redirection_url);
|
||||
|
||||
m_activeReply->deleteLater();
|
||||
m_activeReply = nullptr;
|
||||
|
||||
if (reply_operation == QNetworkAccessManager::GetOperation) {
|
||||
runGetRequest(request);
|
||||
}
|
||||
else if (reply_operation == QNetworkAccessManager::PostOperation) {
|
||||
if (m_inputMultipartData == nullptr) {
|
||||
runPostRequest(request, m_inputData);
|
||||
}
|
||||
else {
|
||||
runPostRequest(request, m_inputMultipartData);
|
||||
}
|
||||
}
|
||||
else if (reply_operation == QNetworkAccessManager::PutOperation) {
|
||||
runPutRequest(request, m_inputData);
|
||||
}
|
||||
else if (reply_operation == QNetworkAccessManager::DeleteOperation) {
|
||||
runDeleteRequest(request);
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_lastOutputMultipartData = decodeMultipartAnswer(reply);
|
||||
// No redirection is indicated. Final file is obtained in our "reply" object.
|
||||
// Read the data into output buffer.
|
||||
if (m_inputMultipartData == nullptr) {
|
||||
m_lastOutputData = reply->readAll();
|
||||
}
|
||||
else {
|
||||
m_lastOutputMultipartData = decodeMultipartAnswer(reply);
|
||||
}
|
||||
|
||||
m_lastContentType = reply->header(QNetworkRequest::ContentTypeHeader);
|
||||
m_lastOutputError = reply->error();
|
||||
m_activeReply->deleteLater();
|
||||
m_activeReply = nullptr;
|
||||
|
||||
if (m_inputMultipartData != nullptr) {
|
||||
m_inputMultipartData->deleteLater();
|
||||
}
|
||||
|
||||
emit completed(m_lastOutputError, m_lastOutputData);
|
||||
}
|
||||
|
||||
m_lastContentType = reply->header(QNetworkRequest::KnownHeaders::ContentTypeHeader);
|
||||
m_lastOutputError = reply->error();
|
||||
m_activeReply->deleteLater();
|
||||
m_activeReply = nullptr;
|
||||
|
||||
if (m_inputMultipartData != nullptr) {
|
||||
m_inputMultipartData->deleteLater();
|
||||
}
|
||||
|
||||
emit completed(m_lastOutputError, m_lastOutputData);
|
||||
}
|
||||
|
||||
void Downloader::progressInternal(qint64 bytes_received, qint64 bytes_total) {
|
||||
|
Loading…
Reference in New Issue
Block a user