Http2: Resend requests on ContentReSend error #7174
authorChristian Kamm <mail@ckamm.de>
Wed, 5 Jun 2019 13:24:57 +0000 (15:24 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:51 +0000 (10:58 +0100)
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.

src/libsync/abstractnetworkjob.cpp
src/libsync/abstractnetworkjob.h
src/libsync/propagatedownload.cpp
test/syncenginetestutils.h

index e44af32a74eb9a52433b7dbf5c231a20fabe151a..ba03b0057d671e0f1437af35ced09aadfbb12a1f 100644 (file)
@@ -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()) {
index b414b55bc84ac846517907671482ecad4d08875c..b92037e9fa391639ec316c470535d853100d1908 100644 (file)
@@ -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.
index 3e9662cefbbdf23809bfc938cff70f767e140c8d..92fa83951349480be53c220662ffa729a4d5b273 100644 (file)
@@ -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;
         }
     }
 
index c34d7b93c56671b7b2969e0da277b14aac4fc18b..f559e16353dc0e5f342ab3cdc7d63b83d8f599c7 100644 (file)
@@ -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;
 };