Skip to content

Commit

Permalink
Merge pull request #962 from cambrialas/feature_http_redirect
Browse files Browse the repository at this point in the history
Enable HTTP redirection on lcHttpManager requests
  • Loading branch information
leozide authored Nov 28, 2024
2 parents 0732221 + f94d757 commit 7fd23da
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions common/lc_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -81,7 +83,17 @@ lcHttpManager::lcHttpManager(QObject* Owner)

lcHttpReply* lcHttpManager::lcHttpManager::DownloadFile(const QString& Url)
{
return (lcHttpReply*)get(QNetworkRequest(QUrl(Url)));
QNetworkRequest Request = QNetworkRequest(QUrl(Url));

#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)
Expand Down

0 comments on commit 7fd23da

Please sign in to comment.