diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 7577f1df92..8e6ec34af8 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -126,7 +126,6 @@ enum { MaxPhotoCaption = 200, MaxMessageSize = 4096, - MaxHttpRedirects = 5, // when getting external data/images WriteMapTimeout = 1000, SaveDraftTimeout = 1000, // save draft after 1 secs of not changing text diff --git a/Telegram/SourceFiles/history/history_location_manager.cpp b/Telegram/SourceFiles/history/history_location_manager.cpp index cf811714a3..adb87c8675 100644 --- a/Telegram/SourceFiles/history/history_location_manager.cpp +++ b/Telegram/SourceFiles/history/history_location_manager.cpp @@ -27,6 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace { constexpr auto kCoordPrecision = 8; +constexpr auto kMaxHttpRedirects = 5; } // namespace @@ -144,7 +145,7 @@ void LocationManager::onFinished(QNetworkReply *reply) { LocationData *d = i.value(); if (serverRedirects.constFind(d) == serverRedirects.cend()) { serverRedirects.insert(d, 1); - } else if (++serverRedirects[d] > MaxHttpRedirects) { + } else if (++serverRedirects[d] > kMaxHttpRedirects) { DEBUG_LOG(("Network Error: Too many HTTP redirects in onFinished() for image link: %1").arg(loc)); return onFailed(reply); } @@ -155,7 +156,7 @@ void LocationManager::onFinished(QNetworkReply *reply) { LocationData *d = i.value(); if (serverRedirects.constFind(d) == serverRedirects.cend()) { serverRedirects.insert(d, 1); - } else if (++serverRedirects[d] > MaxHttpRedirects) { + } else if (++serverRedirects[d] > kMaxHttpRedirects) { DEBUG_LOG(("Network Error: Too many HTTP redirects in onFinished() for image link: %1").arg(loc)); return onFailed(reply); } diff --git a/Telegram/SourceFiles/storage/file_download.cpp b/Telegram/SourceFiles/storage/file_download.cpp index e3563a7fb8..959766feea 100644 --- a/Telegram/SourceFiles/storage/file_download.cpp +++ b/Telegram/SourceFiles/storage/file_download.cpp @@ -493,7 +493,9 @@ void mtpFileLoader::webPartLoaded(int offset, const MTPupload_WebFile &result, m return cancel(true); } auto &webFile = result.c_upload_webFile(); - if (webFile.vsize.v != _size) { + if (!_size) { + _size = webFile.vsize.v; + } else if (webFile.vsize.v != _size) { LOG(("MTP Error: Bad size provided by bot for webDocument: %1, real: %2").arg(_size).arg(webFile.vsize.v)); return cancel(true); } @@ -780,10 +782,7 @@ public: webFileLoaderPrivate(webFileLoader *loader, const QString &url) : _interface(loader) , _url(url) - , _already(0) - , _size(0) - , _reply(0) - , _redirectsLeft(MaxHttpRedirects) { + , _redirectsLeft(kMaxHttpRedirects) { } QNetworkReply *reply() { @@ -830,11 +829,14 @@ public: } private: - webFileLoader *_interface; + static constexpr auto kMaxHttpRedirects = 5; + + webFileLoader *_interface = nullptr; QUrl _url; - qint64 _already, _size; - QNetworkReply *_reply; - int32 _redirectsLeft; + qint64 _already = 0; + qint64 _size = 0; + QNetworkReply *_reply = nullptr; + int32 _redirectsLeft = kMaxHttpRedirects; QByteArray _data; friend class WebLoadManager;