Skip to content

Commit 2353347

Browse files
committed
PropagateDownload: Don't discard the body of error message
We want to keep the body so we can get the message from it (Issue #6459) TestDownload::testErrorMessage did not fail because the FakeErrorReply did not emit readyRead and did not implement bytesAvailable.
1 parent 40d432e commit 2353347

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/libsync/propagatedownload.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ void GETFileJob::slotMetaDataChanged()
165165
// If the status code isn't 2xx, don't write the reply body to the file.
166166
// For any error: handle it when the job is finished, not here.
167167
if (httpStatus / 100 != 2) {
168+
// Disable the buffer limit, as we don't limit the bandwidth for error messages.
169+
// (We are only going to do a readAll() at the end.)
170+
reply()->setReadBufferSize(0);
168171
_device->close();
169172
return;
170173
}
@@ -268,7 +271,7 @@ void GETFileJob::slotReadyRead()
268271
int bufferSize = qMin(1024 * 8ll, reply()->bytesAvailable());
269272
QByteArray buffer(bufferSize, Qt::Uninitialized);
270273

271-
while (reply()->bytesAvailable() > 0) {
274+
while (reply()->bytesAvailable() > 0 && _saveBodyToFile) {
272275
if (_bandwidthChoked) {
273276
qCWarning(lcGetJob) << "Download choked";
274277
break;
@@ -292,7 +295,7 @@ void GETFileJob::slotReadyRead()
292295
return;
293296
}
294297

295-
if (_device->isOpen() && _saveBodyToFile) {
298+
if (_device->isOpen()) {
296299
qint64 w = _device->write(buffer.constData(), r);
297300
if (w != r) {
298301
_errorString = _device->errorString();
@@ -304,7 +307,7 @@ void GETFileJob::slotReadyRead()
304307
}
305308
}
306309

307-
if (reply()->isFinished() && reply()->bytesAvailable() == 0) {
310+
if (reply()->isFinished() && (reply()->bytesAvailable() == 0 || !_saveBodyToFile)) {
308311
qCDebug(lcGetJob) << "Actually finished!";
309312
if (_bandwidthManager) {
310313
_bandwidthManager->unregisterDownloadJob(this);

test/syncenginetestutils.h

+5
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ class FakeErrorReply : public QNetworkReply
728728
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, _httpErrorCode);
729729
setError(InternalServerError, "Internal Server Fake Error");
730730
emit metaDataChanged();
731+
emit readyRead();
732+
setFinished(true);
731733
emit finished();
732734
}
733735

@@ -738,6 +740,9 @@ class FakeErrorReply : public QNetworkReply
738740
_body = _body.mid(max);
739741
return max;
740742
}
743+
qint64 bytesAvailable() const override {
744+
return _body.size();
745+
}
741746

742747
int _httpErrorCode;
743748
QByteArray _body;

0 commit comments

Comments
 (0)