diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index a9aa042bb6..b57dabd775 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -7,6 +7,7 @@ #include "Common/TimeUtil.h" #include "Common/StringUtils.h" #include "Common/System/OSD.h" +#include "Common/System/System.h" #include "Common/Net/SocketCompat.h" #include "Common/Net/Resolve.h" @@ -633,4 +634,14 @@ void HTTPRequest::Do() { completed_ = true; } +std::string RemoveHttpsIfNeeded(std::string_view url) { + if (!System_GetPropertyBool(SYSPROP_SUPPORTS_HTTPS)) { + // Try with http. Needed on Linux installs currently. + if (startsWith(url, "https://")) { + return "http://" + std::string(url.substr(8)); + } + } + return std::string(url); +} + } // namespace http diff --git a/Common/Net/HTTPClient.h b/Common/Net/HTTPClient.h index 2ecc1d1d16..607715086e 100644 --- a/Common/Net/HTTPClient.h +++ b/Common/Net/HTTPClient.h @@ -142,4 +142,6 @@ public: bool Failed() const override { return false; } }; +std::string RemoveHttpsIfNeeded(std::string_view url); + } // namespace http diff --git a/UI/AdhocServerScreen.cpp b/UI/AdhocServerScreen.cpp index ead85be756..6132d4d8a9 100644 --- a/UI/AdhocServerScreen.cpp +++ b/UI/AdhocServerScreen.cpp @@ -51,16 +51,6 @@ static int ParsePortValue(const rapidjson::Value &v) { return -1; } -static std::string RemoveHttpsIfNeeded(std::string_view url) { - if (!System_GetPropertyBool(SYSPROP_SUPPORTS_HTTPS)) { - // Try with http. Needed on Linux installs currently. - if (startsWith(url, "https://")) { - return "http://" + std::string(url.substr(8)); - } - } - return std::string(url); -} - std::vector ParseStatusXML(const std::string& xmlInput) { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_string(xmlInput.c_str()); @@ -301,9 +291,9 @@ AdhocServerInfoScreen::AdhocServerInfoScreen(const AdhocServerListEntry &entry) std::string dataUrl; if (!entry.dataJsonUrl.empty()) { - dataUrl = RemoveHttpsIfNeeded(entry.dataJsonUrl); + dataUrl = http::RemoveHttpsIfNeeded(entry.dataJsonUrl); } else if (!entry.statusXmlUrl.empty()) { - dataUrl = RemoveHttpsIfNeeded(entry.statusXmlUrl); + dataUrl = http::RemoveHttpsIfNeeded(entry.statusXmlUrl); } if (!dataUrl.empty()) {