From: Christian Kamm Date: Wed, 30 Jan 2019 04:43:08 +0000 (+0100) Subject: Download: Ignore content-length for compressed HTTP2/SPDY replies #6885 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~321 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1a250bc3c70028886b572a18b351e02cfa5daf55;p=nextcloud-desktop.git Download: Ignore content-length for compressed HTTP2/SPDY replies #6885 It contains the compressed size. See https://bugreports.qt.io/browse/QTBUG-73364 --- diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 2e305762b..ecbc99188 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -722,8 +722,20 @@ void PropagateDownloadFile::slotGetFinished() */ const QByteArray sizeHeader("Content-Length"); quint64 bodySize = job->reply()->rawHeader(sizeHeader).toULongLong(); + bool hasSizeHeader = !job->reply()->rawHeader(sizeHeader).isEmpty(); + + // Qt removes the content-length header for transparently decompressed HTTP1 replies + // but not for HTTP2 or SPDY replies. For these it remains and contains the size + // of the compressed data. See QTBUG-73364. + const auto contentEncoding = job->reply()->rawHeader("content-encoding").toLower(); + if ((contentEncoding == "gzip" || contentEncoding == "deflate") + && (job->reply()->attribute(QNetworkRequest::HTTP2WasUsedAttribute).toBool() + || job->reply()->attribute(QNetworkRequest::SpdyWasUsedAttribute).toBool())) { + bodySize = 0; + hasSizeHeader = false; + } - if (!job->reply()->rawHeader(sizeHeader).isEmpty() && _tmpFile.size() > 0 && bodySize == 0) { + if (hasSizeHeader && _tmpFile.size() > 0 && bodySize == 0) { // Strange bug with broken webserver or webfirewall https://github.com/owncloud/client/issues/3373#issuecomment-122672322 // This happened when trying to resume a file. The Content-Range header was files, Content-Length was == 0 qCDebug(lcPropagateDownload) << bodySize << _item->_size << _tmpFile.size() << job->resumeStart();