[Pkg-owncloud-commits] [owncloud-client] 06/20: GET: Retry if bad range header used. #2280

Sandro Knauß hefee-guest at moszumanska.debian.org
Fri Oct 24 20:08:12 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch sid
in repository owncloud-client.

commit 395ae1d4ed9d49d26ec9f9f1c987cb2ca4c54fa3
Author: Christian Kamm <kamm at incasoftware.de>
Date:   Wed Oct 8 12:04:17 2014 +0200

    GET: Retry if bad range header used. #2280
    
    * If a 416 is returned and we used a Range header, try again
      from scratch.
    * The direct URL logic was also inconsistent for resumed downloads:
      it sent the Range header but didn't check the returned
      Content-Range header correctly. Now resuming is disabled for
      direct URL downloads.
    
    (cherry picked from commit 48d3c75745e15033f46806fd2386e8ca32d16091)
---
 src/mirall/propagator_qnam.cpp | 37 +++++++++++++++++++++++++++----------
 src/mirall/propagator_qnam.h   |  2 ++
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/src/mirall/propagator_qnam.cpp b/src/mirall/propagator_qnam.cpp
index b5ada9a..610c8ac 100644
--- a/src/mirall/propagator_qnam.cpp
+++ b/src/mirall/propagator_qnam.cpp
@@ -397,6 +397,12 @@ void PropagateUploadFileQNAM::abort()
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 void GETFileJob::start() {
+    if (_resumeStart > 0) {
+        _headers["Range"] = "bytes=" + QByteArray::number(_resumeStart) +'-';
+        _headers["Accept-Ranges"] = "bytes";
+        qDebug() << "Retry with range " << _headers["Range"];
+    }
+
     QNetworkRequest req;
     for(QMap<QByteArray, QByteArray>::const_iterator it = _headers.begin(); it != _headers.end(); ++it) {
         req.setRawHeader(it.key(), it.value());
@@ -560,17 +566,13 @@ void PropagateDownloadFileQNAM::start()
     /* Allow compressed content by setting the header */
     //headers["Accept-Encoding"] = "gzip";
 
-    if (_tmpFile.size() > 0) {
-        quint64 done = _tmpFile.size();
-        if (done == _item._size) {
+    _startSize = _tmpFile.size();
+    if (_startSize > 0) {
+        if (_startSize == _item._size) {
             qDebug() << "File is already complete, no need to download";
             downloadFinished();
             return;
         }
-        headers["Range"] = "bytes=" + QByteArray::number(done) +'-';
-        headers["Accept-Ranges"] = "bytes";
-        qDebug() << "Retry with range " << headers["Range"];
-        _startSize = done;
     }
 
     _job = new GETFileJob(AccountManager::instance()->account(),
@@ -597,18 +599,33 @@ void PropagateDownloadFileQNAM::slotGetFinished()
 
     QNetworkReply::NetworkError err = job->reply()->error();
     if (err != QNetworkReply::NoError) {
-        if (_tmpFile.size() == 0) {
-            // don't keep the temporary file if it is empty.
+        _item._httpErrorCode = job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+
+        // If we sent a 'Range' header and get 416 back, we want to retry
+        // without the header.
+        bool badRangeHeader = job->resumeStart() > 0 && _item._httpErrorCode == 416;
+        if (badRangeHeader) {
+            qDebug() << Q_FUNC_INFO << "server replied 416 to our range request, trying again without in next sync";
+        }
+
+        // Don't keep the temporary file if it is empty or we
+        // used a bad range header.
+        if (_tmpFile.size() == 0 || badRangeHeader) {
             _tmpFile.close();
             _tmpFile.remove();
             _propagator->_journal->setDownloadInfo(_item._file, SyncJournalDb::DownloadInfo());
         }
-        _item._httpErrorCode = job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+
         _propagator->_activeJobs--;
         SyncFileItem::Status status = job->errorStatus();
         if (status == SyncFileItem::NoStatus) {
             status = classifyError(err, _item._httpErrorCode);
         }
+        if (badRangeHeader) {
+            // Can't do this in classifyError() because 416 without a
+            // Range header should result in NormalError.
+            status = SyncFileItem::SoftError;
+        }
         done(status, job->errorString());
         return;
     }
diff --git a/src/mirall/propagator_qnam.h b/src/mirall/propagator_qnam.h
index 7c92b8d..b131ea1 100644
--- a/src/mirall/propagator_qnam.h
+++ b/src/mirall/propagator_qnam.h
@@ -133,6 +133,8 @@ public:
 
     SyncFileItem::Status errorStatus() { return _errorStatus; }
 
+    quint64 resumeStart() const { return _resumeStart; }
+
     virtual void slotTimeout();
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list