From 71518b33365e3cc5b7ca6ecb1f8e919b0da3a74b Mon Sep 17 00:00:00 2001 From: Fabio Barbon Date: Wed, 13 May 2026 15:32:18 +0200 Subject: [PATCH] fix: KOSync authentication with Calibre-Web-Automated (#1951) ## Summary * **What is the goal of this PR?** Fix regression of Calibre-Web-Automated authentication * **What changes are included?** Trivial fix using ESP HTTP Client primitives ## Additional Context Calibre-Web-Automated KOSync stopped working after refactoring HTTP client to use `ESP HTTP Client`, resulting in a _Server error (try again later)_ error. --- ### AI Usage Did you use AI tools to help write this code? _**NO**_ --------- Co-authored-by: drbourbon --- lib/KOReaderSync/KOReaderSyncClient.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/KOReaderSync/KOReaderSyncClient.cpp b/lib/KOReaderSync/KOReaderSyncClient.cpp index e0bc410d..1e4f512d 100644 --- a/lib/KOReaderSync/KOReaderSyncClient.cpp +++ b/lib/KOReaderSync/KOReaderSyncClient.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -75,6 +74,11 @@ esp_http_client_handle_t createClient(const char* url, ResponseBuffer* buf, config.buffer_size_tx = HTTP_BUF_SIZE; config.crt_bundle_attach = esp_crt_bundle_attach; + // HTTP Basic Auth for Calibre-Web-Automated compatibility + config.username = KOREADER_STORE.getUsername().c_str(); + config.password = KOREADER_STORE.getPassword().c_str(); + config.auth_type = HTTP_AUTH_TYPE_BASIC; + esp_http_client_handle_t client = esp_http_client_init(&config); if (!client) return nullptr; @@ -87,16 +91,6 @@ esp_http_client_handle_t createClient(const char* url, ResponseBuffer* buf, return nullptr; } - // HTTP Basic Auth for Calibre-Web-Automated compatibility - std::string credentials = KOREADER_STORE.getUsername() + ":" + KOREADER_STORE.getPassword(); - String encoded = base64::encode(reinterpret_cast(credentials.data()), credentials.size()); - std::string authHeader = "Basic " + std::string(encoded.c_str()); - if (esp_http_client_set_header(client, "Authorization", authHeader.c_str()) != ESP_OK) { - LOG_ERR("KOSync", "Failed to set Authorization header"); - esp_http_client_cleanup(client); - return nullptr; - } - return client; } } // namespace