mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 17:19:09 -04:00
fix(esp_http_client): updated API esp_http_client_get_url to get URL in correct format
This commit updates the API to include the port number in the URL, which was previously missing.
This commit is contained in:
parent
c6637ae369
commit
90d2dbad99
@ -1859,7 +1859,7 @@ esp_err_t esp_http_client_get_url(esp_http_client_handle_t client, char *url, co
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (client->connection_info.host && client->connection_info.scheme && client->connection_info.path) {
|
||||
snprintf(url, len, "%s://%s%s", client->connection_info.scheme, client->connection_info.host, client->connection_info.path);
|
||||
snprintf(url, len, "%s://%s:%d%s", client->connection_info.scheme, client->connection_info.host, client->connection_info.port, client->connection_info.path);
|
||||
return ESP_OK;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to get URL");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -99,7 +99,7 @@ TEST_CASE("Username is unmodified when we change to new path", "[ESP HTTP CLIENT
|
||||
* Explicit APIs esp_http_client_set_username and esp_http_client_set_password are used to change
|
||||
* the auth credentials
|
||||
**/
|
||||
TEST_CASE("Username and password will not reset if new absolute URL doesnot specify auth credentials.", "[ESP HTTP CLIENT]")
|
||||
TEST_CASE("Username and password will not reset if new absolute URL does not specify auth credentials.", "[ESP HTTP CLIENT]")
|
||||
{
|
||||
esp_http_client_config_t config_with_auth = {
|
||||
.host = HOST,
|
||||
@ -146,6 +146,26 @@ TEST_CASE("esp_http_client_init() should return NULL if configured with wrong ur
|
||||
esp_http_client_cleanup(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case to verify that esp_http_client_get_url() returns the URL in the correct format.
|
||||
**/
|
||||
TEST_CASE("esp_http_client_get_url() should return URL in the correct format", "[ESP HTTP CLIENT]")
|
||||
{
|
||||
const char *url = "http://httpbin.org:8080/post";
|
||||
esp_http_client_config_t config = {
|
||||
.url = url,
|
||||
};
|
||||
|
||||
esp_http_client_handle_t client = esp_http_client_init(&config);
|
||||
TEST_ASSERT_NOT_NULL(client);
|
||||
|
||||
char client_url[32];
|
||||
esp_http_client_get_url(client, client_url, sizeof(client_url));
|
||||
esp_http_client_cleanup(client);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(url, client_url);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
unity_run_menu();
|
||||
|
Loading…
x
Reference in New Issue
Block a user