From b2384dc9ee15866ebccd5b7db3c70e9a5c1ea988 Mon Sep 17 00:00:00 2001 From: Vikram Dattu Date: Tue, 23 Apr 2019 19:23:20 +0530 Subject: [PATCH] Add a `esp_http_client_set_redirection` function When using direct operations instead of `esp_http_client_perform`, we need a way to set redirection URL when we get 30x response codes. Added the function for the same. User can now check status code and call `esp_http_client_set_redirection` function to enable redirection. Related change in adf: https://gitlab.espressif.cn:6688/adf/esp-adf-internal/merge_requests/187 Signed-off-by: Vikram Dattu --- components/esp_http_client/esp_http_client.c | 11 +++++++++++ components/esp_http_client/include/esp_http_client.h | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 4a82a50e3..0053090f1 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -567,6 +567,17 @@ esp_err_t esp_http_client_cleanup(esp_http_client_handle_t client) return ESP_OK; } +esp_err_t esp_http_client_set_redirection(esp_http_client_handle_t client) +{ + if (client == NULL) { + return ESP_ERR_INVALID_ARG; + } + if (client->location == NULL) { + return ESP_ERR_INVALID_ARG; + } + return esp_http_client_set_url(client, client->location); +} + static esp_err_t esp_http_check_response(esp_http_client_handle_t client) { char *auth_header = NULL; diff --git a/components/esp_http_client/include/esp_http_client.h b/components/esp_http_client/include/esp_http_client.h index 4e940a6d1..bc83c5fd9 100644 --- a/components/esp_http_client/include/esp_http_client.h +++ b/components/esp_http_client/include/esp_http_client.h @@ -373,6 +373,18 @@ esp_err_t esp_http_client_cleanup(esp_http_client_handle_t client); */ esp_http_client_transport_t esp_http_client_get_transport_type(esp_http_client_handle_t client); +/** + * @brief Set redirection URL. + * When received the 30x code from the server, the client stores the redirect URL provided by the server. + * This function will set the current URL to redirect to enable client to execute the redirection request. + * + * @param[in] client The esp_http_client handle + * + * @return + * - ESP_OK + * - ESP_FAIL + */ +esp_err_t esp_http_client_set_redirection(esp_http_client_handle_t client); #ifdef __cplusplus }