Skip to content

Commit fdfa7d0

Browse files
ckammguruz
authored andcommitted
Download: Ignore content-length for compressed HTTP2/SPDY replies #6885
It contains the compressed size. See https://bugreports.qt.io/browse/QTBUG-73364
1 parent cafd232 commit fdfa7d0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/libsync/propagatedownload.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,20 @@ void PropagateDownloadFile::slotGetFinished()
641641
*/
642642
const QByteArray sizeHeader("Content-Length");
643643
quint64 bodySize = job->reply()->rawHeader(sizeHeader).toULongLong();
644+
bool hasSizeHeader = !job->reply()->rawHeader(sizeHeader).isEmpty();
644645

645-
if (!job->reply()->rawHeader(sizeHeader).isEmpty() && _tmpFile.size() > 0 && bodySize == 0) {
646+
// Qt removes the content-length header for transparently decompressed HTTP1 replies
647+
// but not for HTTP2 or SPDY replies. For these it remains and contains the size
648+
// of the compressed data. See QTBUG-73364.
649+
const auto contentEncoding = job->reply()->rawHeader("content-encoding").toLower();
650+
if ((contentEncoding == "gzip" || contentEncoding == "deflate")
651+
&& (job->reply()->attribute(QNetworkRequest::HTTP2WasUsedAttribute).toBool()
652+
|| job->reply()->attribute(QNetworkRequest::SpdyWasUsedAttribute).toBool())) {
653+
bodySize = 0;
654+
hasSizeHeader = false;
655+
}
656+
657+
if (hasSizeHeader && _tmpFile.size() > 0 && bodySize == 0) {
646658
// Strange bug with broken webserver or webfirewall https://github.com/owncloud/client/issues/3373#issuecomment-122672322
647659
// This happened when trying to resume a file. The Content-Range header was files, Content-Length was == 0
648660
qCDebug(lcPropagateDownload) << bodySize << _item->_size << _tmpFile.size() << job->resumeStart();

0 commit comments

Comments
 (0)