esp_http_client: Add API to get URL from client

Closes: https://github.com/espressif/esp-idf/issues/5115
This commit is contained in:
Shubham Kulkarni 2020-05-07 11:39:46 +05:30
parent a2263571b5
commit 890f541edf
2 changed files with 28 additions and 0 deletions

View file

@ -1332,3 +1332,17 @@ int esp_http_client_read_response(esp_http_client_handle_t client, char *buffer,
}
return read_len;
}
esp_err_t esp_http_client_get_url(esp_http_client_handle_t client, char *url, const int len)
{
if (client == NULL || url == NULL) {
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);
return ESP_OK;
} else {
ESP_LOGE(TAG, "Failed to get URL");
}
return ESP_FAIL;
}

View file

@ -511,6 +511,20 @@ bool esp_http_client_is_complete_data_received(esp_http_client_handle_t client);
int esp_http_client_read_response(esp_http_client_handle_t client, char *buffer, int len);
/**
* @brief Get URL from client
*
* @param[in] client The esp_http_client handle
* @param[inout] url The buffer to store URL
* @param[in] len The buffer length
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t esp_http_client_get_url(esp_http_client_handle_t client, char *url, const int len);
#ifdef __cplusplus
}
#endif