Skip to content

Commit 7351290

Browse files
committed
Merge branch 'bugfix/update_api_to_get_url_correctly_v5.2' into 'release/v5.2'
fix(esp_http_client): updated API esp_http_client_get_url() to get URL in correct format (v5.2) See merge request espressif/esp-idf!36333
2 parents 9c6da59 + 51c668f commit 7351290

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

components/esp_http_client/esp_http_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ esp_err_t esp_http_client_get_url(esp_http_client_handle_t client, char *url, co
17761776
return ESP_ERR_INVALID_ARG;
17771777
}
17781778
if (client->connection_info.host && client->connection_info.scheme && client->connection_info.path) {
1779-
snprintf(url, len, "%s://%s%s", client->connection_info.scheme, client->connection_info.host, client->connection_info.path);
1779+
snprintf(url, len, "%s://%s:%d%s", client->connection_info.scheme, client->connection_info.host, client->connection_info.port, client->connection_info.path);
17801780
return ESP_OK;
17811781
} else {
17821782
ESP_LOGE(TAG, "Failed to get URL");

components/esp_http_client/test_apps/main/test_http_client.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -99,7 +99,7 @@ TEST_CASE("Username is unmodified when we change to new path", "[ESP HTTP CLIENT
9999
* Explicit APIs esp_http_client_set_username and esp_http_client_set_password are used to change
100100
* the auth credentials
101101
**/
102-
TEST_CASE("Username and password will not reset if new absolute URL doesnot specify auth credentials.", "[ESP HTTP CLIENT]")
102+
TEST_CASE("Username and password will not reset if new absolute URL does not specify auth credentials.", "[ESP HTTP CLIENT]")
103103
{
104104
esp_http_client_config_t config_with_auth = {
105105
.host = HOST,
@@ -146,6 +146,26 @@ TEST_CASE("esp_http_client_init() should return NULL if configured with wrong ur
146146
esp_http_client_cleanup(client);
147147
}
148148

149+
/**
150+
* Test case to verify that esp_http_client_get_url() returns the URL in the correct format.
151+
**/
152+
TEST_CASE("esp_http_client_get_url() should return URL in the correct format", "[ESP HTTP CLIENT]")
153+
{
154+
const char *url = "http://httpbin.org:8080/post";
155+
esp_http_client_config_t config = {
156+
.url = url,
157+
};
158+
159+
esp_http_client_handle_t client = esp_http_client_init(&config);
160+
TEST_ASSERT_NOT_NULL(client);
161+
162+
char client_url[32];
163+
esp_http_client_get_url(client, client_url, sizeof(client_url));
164+
esp_http_client_cleanup(client);
165+
166+
TEST_ASSERT_EQUAL_STRING(url, client_url);
167+
}
168+
149169
void app_main(void)
150170
{
151171
unity_run_menu();

0 commit comments

Comments
 (0)