From 489c815eb8ff77ded121671f639c88654f694e4a Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 6 Dec 2019 15:13:10 +0800 Subject: [PATCH] esp_http_client: add esp_http_client_set_authtype function Since currently there are APIs to set url/username/password, it would be good to also allow setting authtype. Link: https://github.com/espressif/esp-idf/issues/4444 Closes https://github.com/espressif/esp-idf/pull/4454 Signed-off-by: Axel Lin --- components/esp_http_client/esp_http_client.c | 10 ++++++++++ components/esp_http_client/include/esp_http_client.h | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 25b9a5e005..3c6b08c648 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -331,6 +331,16 @@ esp_err_t esp_http_client_set_password(esp_http_client_handle_t client, char *pa return ESP_OK; } +esp_err_t esp_http_client_set_authtype(esp_http_client_handle_t client, esp_http_client_auth_type_t auth_type) +{ + if (client == NULL) { + ESP_LOGE(TAG, "client must not be NULL"); + return ESP_ERR_INVALID_ARG; + } + client->connection_info.auth_type = auth_type; + return ESP_OK; +} + static esp_err_t _set_config(esp_http_client_handle_t client, const esp_http_client_config_t *config) { client->connection_info.method = config->method; diff --git a/components/esp_http_client/include/esp_http_client.h b/components/esp_http_client/include/esp_http_client.h index e26849ecaf..8d9243a0ba 100644 --- a/components/esp_http_client/include/esp_http_client.h +++ b/components/esp_http_client/include/esp_http_client.h @@ -307,6 +307,18 @@ esp_err_t esp_http_client_get_password(esp_http_client_handle_t client, char **v */ esp_err_t esp_http_client_set_password(esp_http_client_handle_t client, char *password); +/** + * @brief Set http request auth_type. + * + * @param[in] client The esp_http_client handle + * @param[in] auth_type The esp_http_client auth type + * + * @return + * - ESP_OK + * - ESP_ERR_INVALID_ARG + */ +esp_err_t esp_http_client_set_authtype(esp_http_client_handle_t client, esp_http_client_auth_type_t auth_type); + /** * @brief Set http request method *