From e4e2f88566794f0c07b08037fa840370ccc5735c Mon Sep 17 00:00:00 2001 From: "nilesh.kale" Date: Fri, 29 Aug 2025 11:24:54 +0530 Subject: [PATCH] fix(esp_http_client): fix dispatching of finish event condition This commit updates the condition for dispatching of FINISH event. With this, FINISH event will be dispatched after complete data is read. Closes https://github.com/espressif/esp-idf/issues/17437 --- components/esp_http_client/esp_http_client.c | 6 +++--- components/esp_http_client/include/esp_http_client.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index d13bd15f85..cdfa0a3ab7 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -1454,11 +1454,11 @@ esp_err_t esp_http_client_perform(esp_http_client_handle_t client) if (err != ESP_OK) { http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0); http_dispatch_event_to_event_loop(HTTP_EVENT_ERROR, &client, sizeof(esp_http_client_handle_t)); + } else { + http_dispatch_event(client, HTTP_EVENT_ON_FINISH, NULL, 0); + http_dispatch_event_to_event_loop(HTTP_EVENT_ON_FINISH, &client, sizeof(esp_http_client_handle_t)); } - http_dispatch_event(client, HTTP_EVENT_ON_FINISH, NULL, 0); - http_dispatch_event_to_event_loop(HTTP_EVENT_ON_FINISH, &client, sizeof(esp_http_client_handle_t)); - client->response->buffer->raw_len = 0; if (!http_should_keep_alive(client->parser)) { ESP_LOGD(TAG, "Close connection"); diff --git a/components/esp_http_client/include/esp_http_client.h b/components/esp_http_client/include/esp_http_client.h index 088a57f00a..1f6c388467 100644 --- a/components/esp_http_client/include/esp_http_client.h +++ b/components/esp_http_client/include/esp_http_client.h @@ -40,7 +40,7 @@ typedef enum { and will be deprecated in future versions esp-idf */ HTTP_EVENT_ON_HEADER, /*!< Occurs when receiving each header sent from the server */ HTTP_EVENT_ON_DATA, /*!< Occurs when receiving data from the server, possibly multiple portions of the packet */ - HTTP_EVENT_ON_FINISH, /*!< Occurs when finish a HTTP session */ + HTTP_EVENT_ON_FINISH, /*!< Occurs when complete data is received */ HTTP_EVENT_DISCONNECTED, /*!< The connection has been disconnected */ HTTP_EVENT_REDIRECT, /*!< Intercepting HTTP redirects to handle them manually */ } esp_http_client_event_id_t;