Merge branch 'contrib/github_pr_15715_v5.4' into 'release/v5.4'

fix(esp_http_client): fix error return when set_header has value==NULL (GitHub PR) (v5.4)

See merge request espressif/esp-idf!38264
This commit is contained in:
Mahavir Jain
2025-04-07 15:29:42 +08:00
2 changed files with 22 additions and 2 deletions

View File

@@ -357,7 +357,7 @@ static int http_on_chunk_header(http_parser *parser)
esp_err_t esp_http_client_set_header(esp_http_client_handle_t client, const char *key, const char *value) esp_err_t esp_http_client_set_header(esp_http_client_handle_t client, const char *key, const char *value)
{ {
if (client == NULL || client->request == NULL || client->request->headers == NULL || key == NULL || value == NULL) { if (client == NULL || client->request == NULL || client->request->headers == NULL || key == NULL) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -166,6 +166,26 @@ TEST_CASE("esp_http_client_get_url() should return URL in the correct format", "
TEST_ASSERT_EQUAL_STRING(url, client_url); TEST_ASSERT_EQUAL_STRING(url, client_url);
} }
TEST_CASE("esp_http_client_set_header() should not return error if header value is NULL", "[esp_http_client]")
{
esp_http_client_config_t config = {
.url = "http://httpbin.org:8080/post",
};
esp_http_client_handle_t client = esp_http_client_init(&config);
TEST_ASSERT_NOT_NULL(client);
// First, set a valid header
esp_err_t err = esp_http_client_set_header(client, "Test-Header", "dummy_value");
TEST_ASSERT_EQUAL(ESP_OK, err);
// Now, delete the header by passing value = NULL
err = esp_http_client_set_header(client, "Test-Header", NULL);
TEST_ASSERT_EQUAL(ESP_OK, err); // Ensure it does NOT return ESP_ERR_INVALID_ARG
esp_http_client_cleanup(client);
}
void app_main(void) void app_main(void)
{ {
unity_run_menu(); unity_run_menu();