mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 06:37:38 +03:00
Fixes issue with Calibre web expecting SSL (#347)
http urls now work with Calibre web --------- Co-authored-by: Dave Allie <dave@daveallie.com>
This commit is contained in:
parent
c2fb8ce55d
commit
847786e342
@ -2,13 +2,23 @@
|
||||
|
||||
#include <HTTPClient.h>
|
||||
#include <HardwareSerial.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "util/UrlUtils.h"
|
||||
|
||||
bool HttpDownloader::fetchUrl(const std::string& url, std::string& outContent) {
|
||||
const std::unique_ptr<WiFiClientSecure> client(new WiFiClientSecure());
|
||||
client->setInsecure();
|
||||
// Use WiFiClientSecure for HTTPS, regular WiFiClient for HTTP
|
||||
std::unique_ptr<WiFiClient> client;
|
||||
if (UrlUtils::isHttpsUrl(url)) {
|
||||
auto* secureClient = new WiFiClientSecure();
|
||||
secureClient->setInsecure();
|
||||
client.reset(secureClient);
|
||||
} else {
|
||||
client.reset(new WiFiClient());
|
||||
}
|
||||
HTTPClient http;
|
||||
|
||||
Serial.printf("[%lu] [HTTP] Fetching: %s\n", millis(), url.c_str());
|
||||
@ -33,8 +43,15 @@ bool HttpDownloader::fetchUrl(const std::string& url, std::string& outContent) {
|
||||
|
||||
HttpDownloader::DownloadError HttpDownloader::downloadToFile(const std::string& url, const std::string& destPath,
|
||||
ProgressCallback progress) {
|
||||
const std::unique_ptr<WiFiClientSecure> client(new WiFiClientSecure());
|
||||
client->setInsecure();
|
||||
// Use WiFiClientSecure for HTTPS, regular WiFiClient for HTTP
|
||||
std::unique_ptr<WiFiClient> client;
|
||||
if (UrlUtils::isHttpsUrl(url)) {
|
||||
auto* secureClient = new WiFiClientSecure();
|
||||
secureClient->setInsecure();
|
||||
client.reset(secureClient);
|
||||
} else {
|
||||
client.reset(new WiFiClient());
|
||||
}
|
||||
HTTPClient http;
|
||||
|
||||
Serial.printf("[%lu] [HTTP] Downloading: %s\n", millis(), url.c_str());
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
namespace UrlUtils {
|
||||
|
||||
bool isHttpsUrl(const std::string& url) { return url.rfind("https://", 0) == 0; }
|
||||
|
||||
std::string ensureProtocol(const std::string& url) {
|
||||
if (url.find("://") == std::string::npos) {
|
||||
return "http://" + url;
|
||||
|
||||
@ -3,6 +3,11 @@
|
||||
|
||||
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)
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user