From 1c5118e2a57a51e5a73794dc6553d2d7c0313529 Mon Sep 17 00:00:00 2001 From: movsb Date: Fri, 5 Jan 2024 18:44:41 +0800 Subject: [PATCH] fix(esp_https_ota): only do ota when http status code is 200 --- components/esp_https_ota/src/esp_https_ota.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/esp_https_ota/src/esp_https_ota.c b/components/esp_https_ota/src/esp_https_ota.c index d326c2bea..1168f61e4 100644 --- a/components/esp_https_ota/src/esp_https_ota.c +++ b/components/esp_https_ota/src/esp_https_ota.c @@ -64,6 +64,13 @@ esp_err_t esp_https_ota(const esp_http_client_config_t *config) } esp_http_client_fetch_headers(client); + int statusCode = esp_http_client_get_status_code(client); + if (statusCode != 200) { + ESP_LOGE(TAG, "Received incorrect HTTP status code: %d (expected: 200)", statusCode); + http_cleanup(client); + return ESP_FAIL; + } + esp_ota_handle_t update_handle = 0; const esp_partition_t *update_partition = NULL; ESP_LOGI(TAG, "Starting OTA...");