aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/jobs/basejob.cpp24
-rw-r--r--lib/jobs/basejob.h3
-rw-r--r--lib/jobs/downloadfilejob.cpp20
3 files changed, 28 insertions, 19 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp
index a23f43b3..4e35cb01 100644
--- a/lib/jobs/basejob.cpp
+++ b/lib/jobs/basejob.cpp
@@ -242,6 +242,8 @@ void BaseJob::sendRequest()
connect( d->reply.data(), &QNetworkReply::finished, this, &BaseJob::gotReply );
if (d->reply->isRunning())
{
+ connect( d->reply.data(), &QNetworkReply::metaDataChanged,
+ this, &BaseJob::checkReply);
connect( d->reply.data(), &QNetworkReply::uploadProgress,
this, &BaseJob::uploadProgress);
connect( d->reply.data(), &QNetworkReply::downloadProgress,
@@ -254,13 +256,22 @@ void BaseJob::sendRequest()
qCWarning(d->logCat) << this << "request could not start";
}
+void BaseJob::checkReply()
+{
+ setStatus(doCheckReply(d->reply.data()));
+}
+
void BaseJob::gotReply()
{
- setStatus(checkReply(d->reply.data()));
+ checkReply();
+ qCDebug(d->logCat).nospace().noquote() << this << " returned HTTP code "
+ << d->reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()
+ << ": " << (d->reply->error() == QNetworkReply::NoError ?
+ "Success" : d->reply->errorString())
+ << " (URL: " << d->reply->url().toDisplayString() << ")";
if (status().good())
setStatus(parseReply(d->reply.data()));
- else
- {
+ else {
const auto body = d->reply->readAll();
if (!body.isEmpty())
{
@@ -324,15 +335,10 @@ bool checkContentType(const QByteArray& type, const QByteArrayList& patterns)
return false;
}
-BaseJob::Status BaseJob::checkReply(QNetworkReply* reply) const
+BaseJob::Status BaseJob::doCheckReply(QNetworkReply* reply) const
{
const auto httpCode =
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
- qCDebug(d->logCat).nospace().noquote() << this << " returned HTTP code "
- << httpCode << ": "
- << (reply->error() == QNetworkReply::NoError ?
- "Success" : reply->errorString())
- << " (URL: " << reply->url().toDisplayString() << ")";
if (httpCode == 429) // Qt doesn't know about it yet
return { TooManyRequestsError, tr("Too many requests") };
diff --git a/lib/jobs/basejob.h b/lib/jobs/basejob.h
index 252b8ea0..f243066f 100644
--- a/lib/jobs/basejob.h
+++ b/lib/jobs/basejob.h
@@ -248,7 +248,7 @@ namespace QMatrixClient
*
* @see gotReply
*/
- virtual Status checkReply(QNetworkReply* reply) const;
+ virtual Status doCheckReply(QNetworkReply* reply) const;
/**
* Processes the reply. By default, parses the reply into
@@ -286,6 +286,7 @@ namespace QMatrixClient
private slots:
void sendRequest();
+ void checkReply();
void gotReply();
private:
diff --git a/lib/jobs/downloadfilejob.cpp b/lib/jobs/downloadfilejob.cpp
index 6a3d8483..2bf9dd8f 100644
--- a/lib/jobs/downloadfilejob.cpp
+++ b/lib/jobs/downloadfilejob.cpp
@@ -62,6 +62,8 @@ void DownloadFileJob::beforeStart(const ConnectionData*)
void DownloadFileJob::afterStart(const ConnectionData*, QNetworkReply* reply)
{
connect(reply, &QNetworkReply::metaDataChanged, this, [this,reply] {
+ if (!status().good())
+ return;
auto sizeHeader = reply->header(QNetworkRequest::ContentLengthHeader);
if (sizeHeader.isValid())
{
@@ -77,15 +79,15 @@ void DownloadFileJob::afterStart(const ConnectionData*, QNetworkReply* reply)
}
});
connect(reply, &QIODevice::readyRead, this, [this,reply] {
- auto bytes = reply->read(reply->bytesAvailable());
- if (bytes.isEmpty())
- {
- qCWarning(JOBS)
- << "Unexpected empty chunk when downloading from"
- << reply->url() << "to" << d->tempFile->fileName();
- } else {
- d->tempFile->write(bytes);
- }
+ if (!status().good())
+ return;
+ auto bytes = reply->read(reply->bytesAvailable());
+ if (!bytes.isEmpty())
+ d->tempFile->write(bytes);
+ else
+ qCWarning(JOBS)
+ << "Unexpected empty chunk when downloading from"
+ << reply->url() << "to" << d->tempFile->fileName();
});
}