From 96a8316e71d1ac691fd858d9fc93e37eb6e03f38 Mon Sep 17 00:00:00 2001 From: Harshit Malpani Date: Fri, 8 Sep 2023 14:03:04 +0530 Subject: [PATCH] feat(esp_http_client): Add API to set auth data This new API can be used to set the authentication data in the client context when the auth data is received in the custom header Closes: https://github.com/espressif/esp-idf/pull/12131 --- components/esp_http_client/esp_http_client.c | 9 +++++++++ .../esp_http_client/include/esp_http_client.h | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 61faf21357..feb3891af0 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -1645,6 +1645,15 @@ esp_http_client_transport_t esp_http_client_get_transport_type(esp_http_client_h } } +esp_err_t esp_http_client_set_auth_data(esp_http_client_handle_t client, const char *auth_data, int len) +{ + if (client == NULL || auth_data == NULL || len <= 0) { + return ESP_ERR_INVALID_ARG; + } + http_utils_append_string(&client->auth_header, auth_data, len); + return ESP_OK; +} + void esp_http_client_add_auth(esp_http_client_handle_t client) { if (client == NULL) { diff --git a/components/esp_http_client/include/esp_http_client.h b/components/esp_http_client/include/esp_http_client.h index c125c9d468..6135976d56 100644 --- a/components/esp_http_client/include/esp_http_client.h +++ b/components/esp_http_client/include/esp_http_client.h @@ -600,6 +600,21 @@ esp_http_client_transport_t esp_http_client_get_transport_type(esp_http_client_h */ esp_err_t esp_http_client_set_redirection(esp_http_client_handle_t client); +/** + * @brief On receiving a custom authentication header, this API can be invoked to set the + * authentication information from the header. This API can be called from the event + * handler. + * + * @param[in] client The esp_http_client handle + * @param[in] auth_data The authentication data received in the header + * @param[in] len length of auth_data. + * + * @return + * - ESP_ERR_INVALID_ARG + * - ESP_OK + */ +esp_err_t esp_http_client_set_auth_data(esp_http_client_handle_t client, const char *auth_data, int len); + /** * @brief On receiving HTTP Status code 401, this API can be invoked to add authorization * information.