fix(esp_http_client): Added test case to verify set header functionality

This commit added testcase to verify esp_http_client_set_header
allows header value as NULL. Setting this NULL will delete the header.

Closes https://github.com/espressif/esp-idf/issues/15714
This commit is contained in:
nilesh.kale
2025-04-04 15:54:53 +05:30
committed by Mahavir Jain
parent 3c59f9e682
commit 9c4c366d61

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
*/
@@ -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_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)
{
unity_run_menu();