From 42756f7effb2df498df524750bc9fe016f081fef Mon Sep 17 00:00:00 2001 From: Harshit Malpani Date: Thu, 1 Sep 2022 12:04:40 +0530 Subject: [PATCH] esp_https_ota: fix bug where `http_client_init_cb` is called after `esp_http_client_perform()` instead of before. Closes https://github.com/espressif/esp-idf/issues/9581 --- components/esp_https_ota/src/esp_https_ota.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/components/esp_https_ota/src/esp_https_ota.c b/components/esp_https_ota/src/esp_https_ota.c index 2734a20a3f7d..d143b9e5608e 100644 --- a/components/esp_https_ota/src/esp_https_ota.c +++ b/components/esp_https_ota/src/esp_https_ota.c @@ -220,6 +220,14 @@ esp_err_t esp_https_ota_begin(esp_https_ota_config_t *ota_config, esp_https_ota_ goto failure; } + if (ota_config->http_client_init_cb) { + err = ota_config->http_client_init_cb(https_ota_handle->http_client); + if (err != ESP_OK) { + ESP_LOGE(TAG, "http_client_init_cb returned 0x%x", err); + goto http_cleanup; + } + } + if (https_ota_handle->partial_http_download) { esp_http_client_set_method(https_ota_handle->http_client, HTTP_METHOD_HEAD); err = esp_http_client_perform(https_ota_handle->http_client); @@ -252,14 +260,6 @@ esp_err_t esp_https_ota_begin(esp_https_ota_config_t *ota_config, esp_https_ota_ esp_http_client_set_method(https_ota_handle->http_client, HTTP_METHOD_GET); } - if (ota_config->http_client_init_cb) { - err = ota_config->http_client_init_cb(https_ota_handle->http_client); - if (err != ESP_OK) { - ESP_LOGE(TAG, "http_client_init_cb returned 0x%x", err); - goto http_cleanup; - } - } - err = _http_connect(https_ota_handle->http_client); if (err != ESP_OK) { ESP_LOGE(TAG, "Failed to establish HTTP connection");