Move isHttpsUrl to UrlUtils
This commit is contained in:
parent
fae1e33a17
commit
9e6fb95e0f
@ -7,14 +7,12 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace {
|
#include "util/UrlUtils.h"
|
||||||
bool isHttpsUrl(const std::string& url) { return url.rfind("https://", 0) == 0; }
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
bool HttpDownloader::fetchUrl(const std::string& url, std::string& outContent) {
|
bool HttpDownloader::fetchUrl(const std::string& url, std::string& outContent) {
|
||||||
// Use WiFiClientSecure for HTTPS, regular WiFiClient for HTTP
|
// Use WiFiClientSecure for HTTPS, regular WiFiClient for HTTP
|
||||||
std::unique_ptr<WiFiClient> client;
|
std::unique_ptr<WiFiClient> client;
|
||||||
if (isHttpsUrl(url)) {
|
if (UrlUtils::isHttpsUrl(url)) {
|
||||||
auto* secureClient = new WiFiClientSecure();
|
auto* secureClient = new WiFiClientSecure();
|
||||||
secureClient->setInsecure();
|
secureClient->setInsecure();
|
||||||
client.reset(secureClient);
|
client.reset(secureClient);
|
||||||
@ -47,7 +45,7 @@ HttpDownloader::DownloadError HttpDownloader::downloadToFile(const std::string&
|
|||||||
ProgressCallback progress) {
|
ProgressCallback progress) {
|
||||||
// Use WiFiClientSecure for HTTPS, regular WiFiClient for HTTP
|
// Use WiFiClientSecure for HTTPS, regular WiFiClient for HTTP
|
||||||
std::unique_ptr<WiFiClient> client;
|
std::unique_ptr<WiFiClient> client;
|
||||||
if (isHttpsUrl(url)) {
|
if (UrlUtils::isHttpsUrl(url)) {
|
||||||
auto* secureClient = new WiFiClientSecure();
|
auto* secureClient = new WiFiClientSecure();
|
||||||
secureClient->setInsecure();
|
secureClient->setInsecure();
|
||||||
client.reset(secureClient);
|
client.reset(secureClient);
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace UrlUtils {
|
namespace UrlUtils {
|
||||||
|
|
||||||
|
bool isHttpsUrl(const std::string& url) { return url.rfind("https://", 0) == 0; }
|
||||||
|
|
||||||
std::string ensureProtocol(const std::string& url) {
|
std::string ensureProtocol(const std::string& url) {
|
||||||
if (url.find("://") == std::string::npos) {
|
if (url.find("://") == std::string::npos) {
|
||||||
return "http://" + url;
|
return "http://" + url;
|
||||||
|
|||||||
@ -3,6 +3,11 @@
|
|||||||
|
|
||||||
namespace UrlUtils {
|
namespace UrlUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if URL uses HTTPS protocol
|
||||||
|
*/
|
||||||
|
bool isHttpsUrl(const std::string& url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepend http:// if no protocol specified (server will redirect to https if needed)
|
* Prepend http:// if no protocol specified (server will redirect to https if needed)
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user