Ensure redirects to HTTPS are enabled/allowed regardless of the Qt version

Technically, this is not completely true because it is not supported on Qt
versions older than 5.9.
This commit is contained in:
Martchus 2023-09-04 20:33:32 +02:00
parent b7d19ea904
commit 669923dbb6
2 changed files with 7 additions and 0 deletions

View File

@ -616,6 +616,8 @@ section.
* Pausing/resuming folders and devices doesn't work when using scan-intervals with a lot of zeros because of
Syncthing bug https://github.com/syncthing/syncthing/issues/4001. This has already been fixed on the Qt-side with
https://codereview.qt-project.org/#/c/187069/. However, the fix is only available in Qt 5.9 and above.
* Redirections cannot be followed (e.g. from HTTP to HTTPS) because
`QNetworkRequest::RedirectPolicyAttribute` and `QNetworkRequest::NoLessSafeRedirectPolicy` are not available yet.
* any Qt version:
* The tray disconnects from the local instance when the network connection goes down. The network connection must be restored
or the tray restarted to be able to connect to local Syncthing again. This is caused by Qt bug

View File

@ -43,6 +43,11 @@ QNetworkRequest SyncthingConnection::prepareRequest(const QString &path, const Q
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, QByteArrayLiteral("application/x-www-form-urlencoded"));
request.setRawHeader("X-API-Key", m_apiKey);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
// ensure redirects to HTTPS are enabled/allowed regardless of the Qt version
// note: This setting is only the default as of Qt 6 and only supported as of Qt 5.9.
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
request.setTransferTimeout(noTimeout ? 0 : m_requestTimeout);
#endif