Merge pull request #62 from jpirnay/fix-redirect-ota

fix: Acknowledge http redirects during OTA (partial adaption of PR 1336)
This commit is contained in:
jpirnay
2026-04-11 20:54:43 +02:00
committed by GitHub
2 changed files with 13 additions and 6 deletions
+8 -2
View File
@@ -67,7 +67,8 @@ bool HttpDownloader::fetchUrl(const std::string& url, Stream& outContent) {
LOG_DBG("HTTP", "Fetching: %s", url.c_str()); LOG_DBG("HTTP", "Fetching: %s", url.c_str());
http.begin(*client, url.c_str()); http.begin(*client, url.c_str());
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
http.setTimeout(30000);
http.addHeader("User-Agent", "CrossPoint-ESP32-" CROSSPOINT_VERSION); http.addHeader("User-Agent", "CrossPoint-ESP32-" CROSSPOINT_VERSION);
// Add Basic HTTP auth if credentials are configured // Add Basic HTTP auth if credentials are configured
@@ -118,7 +119,8 @@ HttpDownloader::DownloadError HttpDownloader::downloadToFile(const std::string&
LOG_DBG("HTTP", "Destination: %s", destPath.c_str()); LOG_DBG("HTTP", "Destination: %s", destPath.c_str());
http.begin(*client, url.c_str()); http.begin(*client, url.c_str());
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
http.setTimeout(65535); // max uint16_t (~65s) — HTTPClient::setTimeout takes uint16_t ms
http.addHeader("User-Agent", "CrossPoint-ESP32-" CROSSPOINT_VERSION); http.addHeader("User-Agent", "CrossPoint-ESP32-" CROSSPOINT_VERSION);
// Add Basic HTTP auth if credentials are configured // Add Basic HTTP auth if credentials are configured
@@ -160,6 +162,10 @@ HttpDownloader::DownloadError HttpDownloader::downloadToFile(const std::string&
FileWriteStream fileStream(file, contentLength, progress); FileWriteStream fileStream(file, contentLength, progress);
const int writeResult = http.writeToStream(&fileStream); const int writeResult = http.writeToStream(&fileStream);
// Flush before closing to ensure data is written to the SD card.
// Without this, Storage.exists() might return false immediately after
// even though the file was written (FAT not yet updated on disk).
file.flush();
file.close(); file.close();
http.end(); http.end();
+5 -4
View File
@@ -71,7 +71,6 @@ OtaUpdater::OtaUpdaterError OtaUpdater::checkForUpdate() {
/* Default HTTP client buffer size 512 byte only */ /* Default HTTP client buffer size 512 byte only */
.buffer_size = 8192, .buffer_size = 8192,
.buffer_size_tx = 8192, .buffer_size_tx = 8192,
.skip_cert_common_name_check = true,
.crt_bundle_attach = esp_crt_bundle_attach, .crt_bundle_attach = esp_crt_bundle_attach,
.keep_alive_enable = true, .keep_alive_enable = true,
}; };
@@ -212,14 +211,16 @@ OtaUpdater::OtaUpdaterError OtaUpdater::installUpdate() {
esp_http_client_config_t client_config = { esp_http_client_config_t client_config = {
.url = otaUrl.c_str(), .url = otaUrl.c_str(),
.timeout_ms = 15000, .timeout_ms = 30000,
/* Default HTTP client buffer size 512 byte only /* Default HTTP client buffer size 512 byte only
* not sufficent to handle URL redirection cases or * not sufficient to handle URL redirection cases or
* parsing of large HTTP headers. * parsing of large HTTP headers.
*/ */
.max_redirection_count = 5,
.buffer_size = 8192, .buffer_size = 8192,
.buffer_size_tx = 8192, .buffer_size_tx = 8192,
.skip_cert_common_name_check = true, /* GitHub release assets redirect to objects.githubusercontent.com CDN.
* Without max_redirection_count, esp_https_ota downloads 0 bytes and stalls. */
.crt_bundle_attach = esp_crt_bundle_attach, .crt_bundle_attach = esp_crt_bundle_attach,
.keep_alive_enable = true, .keep_alive_enable = true,
}; };