Download: Don't store message body if status != 2xx #2280

This commit is contained in:
Christian Kamm 2014-10-08 14:09:57 +02:00
parent 48d3c75745
commit 705cd571a5

View file

@ -482,9 +482,15 @@ void GETFileJob::start() {
void GETFileJob::slotMetaDataChanged()
{
if (reply()->error() != QNetworkReply::NoError
|| reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() / 100 != 2) {
// We will handle the error when the job is finished.
int httpStatus = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
// If the status code isn't 2xx, don't write the reply body to the file.
// For any error: handle it when the job is finished, not here.
if (httpStatus / 100 != 2) {
_device->close();
return;
}
if (reply()->error() != QNetworkReply::NoError) {
return;
}
_etag = get_etag_from_reply(reply());
@ -554,6 +560,7 @@ void GETFileJob::slotReadyRead()
return;
}
if (_device->isOpen()) {
qint64 w = _device->write(buffer.constData(), r);
if (w != r) {
_errorString = _device->errorString();
@ -564,6 +571,7 @@ void GETFileJob::slotReadyRead()
}
}
}
}
void GETFileJob::slotTimeout()
{