fix: use esp_http_client for KOSync to prevent TLS OOM on ESP32-C3
The Arduino WiFiClientSecure allocates 16KB TLS buffers by default, which exhausts the ESP32-C3's limited heap (~46KB free after WiFi) during the TLS handshake. This causes KOReader sync to fail silently or crash on HTTPS servers (including the default sync.koreader.rocks). Replace WiFiClientSecure/HTTPClient with esp_http_client (ESP-IDF), which supports configurable buffer sizes. Use 2KB TLS buffers — more than sufficient for KOSync's tiny JSON payloads (<1KB). Also: - Use esp_crt_bundle for proper TLS certificate verification instead of setInsecure() - Strip trailing slashes from server URL to prevent double-slash in API paths - Add lastHttpCode for diagnostics - Add heap logging to help debug memory issues Fixes #581 (cherry picked from commit 835abc19ff14fcbea8571ccb0dfd8d21e882b84c)
This commit is contained in:
@@ -153,16 +153,22 @@ void KOReaderCredentialStore::setServerUrl(const std::string& url) {
|
||||
}
|
||||
|
||||
std::string KOReaderCredentialStore::getBaseUrl() const {
|
||||
std::string url;
|
||||
if (serverUrl.empty()) {
|
||||
return DEFAULT_SERVER_URL;
|
||||
url = DEFAULT_SERVER_URL;
|
||||
} else if (serverUrl.find("://") == std::string::npos) {
|
||||
// Normalize URL: add http:// if no protocol specified (local servers typically don't have SSL)
|
||||
url = "http://" + serverUrl;
|
||||
} else {
|
||||
url = serverUrl;
|
||||
}
|
||||
|
||||
// Normalize URL: add http:// if no protocol specified (local servers typically don't have SSL)
|
||||
if (serverUrl.find("://") == std::string::npos) {
|
||||
return "http://" + serverUrl;
|
||||
// Strip trailing slashes to avoid double-slash in API paths
|
||||
while (!url.empty() && url.back() == '/') {
|
||||
url.pop_back();
|
||||
}
|
||||
|
||||
return serverUrl;
|
||||
return url;
|
||||
}
|
||||
|
||||
void KOReaderCredentialStore::setMatchMethod(DocumentMatchMethod method) {
|
||||
|
||||
Reference in New Issue
Block a user