From 0bd6fa3151978198bf6d8778df692c7a310e48fb Mon Sep 17 00:00:00 2001 From: cambrialas Date: Wed, 27 Nov 2024 21:33:07 +0100 Subject: [PATCH 1/2] lcHttpManager enable HTTP redirection --- common/lc_http.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/lc_http.cpp b/common/lc_http.cpp index 0cfca2c8..e85cfb5b 100644 --- a/common/lc_http.cpp +++ b/common/lc_http.cpp @@ -81,7 +81,10 @@ lcHttpManager::lcHttpManager(QObject* Owner) lcHttpReply* lcHttpManager::lcHttpManager::DownloadFile(const QString& Url) { - return (lcHttpReply*)get(QNetworkRequest(QUrl(Url))); + QNetworkRequest req = QNetworkRequest(QUrl(Url)); + req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); + + return (lcHttpReply*)get(req); } void lcHttpManager::Finished(QNetworkReply* Reply) From f94d7575000e52d51280850f580d1b6b1c70945f Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Thu, 28 Nov 2024 13:07:29 -0800 Subject: [PATCH 2/2] Added Qt version checks. --- common/lc_http.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/common/lc_http.cpp b/common/lc_http.cpp index e85cfb5b..7a6c6c44 100644 --- a/common/lc_http.cpp +++ b/common/lc_http.cpp @@ -22,10 +22,12 @@ void lcHttpReply::run() static_assert(sizeof(wchar_t) == sizeof(QChar), "Character size mismatch"); Session = InternetOpen(L"LeoCAD", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); + if (!Session) return; - Request = InternetOpenUrl(Session, (WCHAR*)mURL.data(), NULL, 0, 0, 0); + Request = InternetOpenUrl(Session, (WCHAR*)mURL.data(), NULL, 0, INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP, 0); + if (!Request) { InternetCloseHandle(Session); @@ -81,10 +83,17 @@ lcHttpManager::lcHttpManager(QObject* Owner) lcHttpReply* lcHttpManager::lcHttpManager::DownloadFile(const QString& Url) { - QNetworkRequest req = QNetworkRequest(QUrl(Url)); - req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); + QNetworkRequest Request = QNetworkRequest(QUrl(Url)); - return (lcHttpReply*)get(req); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) // default changed in Qt6 +#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) + Request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); +#elif (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + Request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); +#endif +#endif + + return (lcHttpReply*)get(Request); } void lcHttpManager::Finished(QNetworkReply* Reply)