From: Christian Kamm Date: Wed, 5 Jun 2019 13:24:57 +0000 (+0200) Subject: Http2: Resend requests on ContentReSend error #7174 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~231 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a7852e3aba13756662ae9db6ed4bc3da4700f41a;p=nextcloud-desktop.git Http2: Resend requests on ContentReSend error #7174 Since Qt does not yet transparently resend HTTP2 requests in some cases we do it manually. The test showed a problem where the initial non-200 reply would close the target temporary file and the follow-up request couldn't store any data. Removing that close() call is safe because there also is a _saveBodyToFile flag that guards writes to the target file. --- diff --git a/src/libsync/abstractnetworkjob.cpp b/src/libsync/abstractnetworkjob.cpp index e44af32a7..ba03b0057 100644 --- a/src/libsync/abstractnetworkjob.cpp +++ b/src/libsync/abstractnetworkjob.cpp @@ -163,7 +163,6 @@ void AbstractNetworkJob::slotFinished() qCWarning(lcNetworkJob) << "SslHandshakeFailedError: " << errorString() << " : can be caused by a webserver wanting SSL client certificates"; } -#if (QT_VERSION >= 0x050800) // Qt doesn't yet transparently resend HTTP2 requests, do so here const auto maxHttp2Resends = 3; QByteArray verb = requestVerb(*reply()); @@ -194,7 +193,6 @@ void AbstractNetworkJob::slotFinished() return; } } -#endif if (_reply->error() != QNetworkReply::NoError) { @@ -234,7 +232,6 @@ void AbstractNetworkJob::slotFinished() // ### some of the qWarnings here should be exported via displayErrors() so they // ### can be presented to the user if the job executor has a GUI - QByteArray verb = requestVerb(*reply()); if (requestedUrl.scheme() == QLatin1String("https") && redirectUrl.scheme() == QLatin1String("http")) { qCWarning(lcNetworkJob) << this << "HTTPS->HTTP downgrade detected!"; } else if (requestedUrl == redirectUrl || _redirectCount + 1 >= maxRedirects()) { diff --git a/src/libsync/abstractnetworkjob.h b/src/libsync/abstractnetworkjob.h index b414b55bc..b92037e9f 100644 --- a/src/libsync/abstractnetworkjob.h +++ b/src/libsync/abstractnetworkjob.h @@ -195,9 +195,7 @@ private: QString _path; QTimer _timer; int _redirectCount = 0; -#if (QT_VERSION >= 0x050800) int _http2ResendCount = 0; -#endif // Set by the xyzRequest() functions and needed to be able to redirect // requests, should it be required. diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 3e9662cef..92fa83951 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -314,15 +314,13 @@ void GETFileJob::slotReadyRead() return; } - if (_device->isOpen()) { - qint64 w = _device->write(buffer.constData(), r); - if (w != r) { - _errorString = _device->errorString(); - _errorStatus = SyncFileItem::NormalError; - qCWarning(lcGetJob) << "Error while writing to file" << w << r << _errorString; - reply()->abort(); - return; - } + qint64 w = _device->write(buffer.constData(), r); + if (w != r) { + _errorString = _device->errorString(); + _errorStatus = SyncFileItem::NormalError; + qCWarning(lcGetJob) << "Error while writing to file" << w << r << _errorString; + reply()->abort(); + return; } } diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index c34d7b93c..f559e1635 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -780,7 +780,7 @@ class FakeErrorReply : public QNetworkReply public: FakeErrorReply(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QObject *parent, int httpErrorCode, const QByteArray &body = QByteArray()) - : QNetworkReply{parent}, _httpErrorCode(httpErrorCode), _body(body) { + : QNetworkReply{parent}, _body(body) { setRequest(request); setUrl(request.url()); setOperation(op); @@ -819,7 +819,6 @@ public: return _body.size(); } - int _httpErrorCode; QByteArray _body; };