A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fixes issue with Calibre web expecting SSL (#347)

http urls now work with Calibre web

---------

Co-authored-by: Dave Allie <dave@daveallie.com>

authored by

Justin Mitchell
Dave Allie
and committed by
GitHub
847786e3 c2fb8ce5

+28 -4
+21 -4
src/network/HttpDownloader.cpp
··· 2 2 3 3 #include <HTTPClient.h> 4 4 #include <HardwareSerial.h> 5 + #include <WiFiClient.h> 5 6 #include <WiFiClientSecure.h> 6 7 7 8 #include <memory> 8 9 10 + #include "util/UrlUtils.h" 11 + 9 12 bool HttpDownloader::fetchUrl(const std::string& url, std::string& outContent) { 10 - const std::unique_ptr<WiFiClientSecure> client(new WiFiClientSecure()); 11 - client->setInsecure(); 13 + // Use WiFiClientSecure for HTTPS, regular WiFiClient for HTTP 14 + std::unique_ptr<WiFiClient> client; 15 + if (UrlUtils::isHttpsUrl(url)) { 16 + auto* secureClient = new WiFiClientSecure(); 17 + secureClient->setInsecure(); 18 + client.reset(secureClient); 19 + } else { 20 + client.reset(new WiFiClient()); 21 + } 12 22 HTTPClient http; 13 23 14 24 Serial.printf("[%lu] [HTTP] Fetching: %s\n", millis(), url.c_str()); ··· 33 43 34 44 HttpDownloader::DownloadError HttpDownloader::downloadToFile(const std::string& url, const std::string& destPath, 35 45 ProgressCallback progress) { 36 - const std::unique_ptr<WiFiClientSecure> client(new WiFiClientSecure()); 37 - client->setInsecure(); 46 + // Use WiFiClientSecure for HTTPS, regular WiFiClient for HTTP 47 + std::unique_ptr<WiFiClient> client; 48 + if (UrlUtils::isHttpsUrl(url)) { 49 + auto* secureClient = new WiFiClientSecure(); 50 + secureClient->setInsecure(); 51 + client.reset(secureClient); 52 + } else { 53 + client.reset(new WiFiClient()); 54 + } 38 55 HTTPClient http; 39 56 40 57 Serial.printf("[%lu] [HTTP] Downloading: %s\n", millis(), url.c_str());
+2
src/util/UrlUtils.cpp
··· 2 2 3 3 namespace UrlUtils { 4 4 5 + bool isHttpsUrl(const std::string& url) { return url.rfind("https://", 0) == 0; } 6 + 5 7 std::string ensureProtocol(const std::string& url) { 6 8 if (url.find("://") == std::string::npos) { 7 9 return "http://" + url;
+5
src/util/UrlUtils.h
··· 4 4 namespace UrlUtils { 5 5 6 6 /** 7 + * Check if URL uses HTTPS protocol 8 + */ 9 + bool isHttpsUrl(const std::string& url); 10 + 11 + /** 7 12 * Prepend http:// if no protocol specified (server will redirect to https if needed) 8 13 */ 9 14 std::string ensureProtocol(const std::string& url);