From 32e78b71f3469b8992e8f42036b5dcb8dd879f31 Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Mon, 30 Jan 2023 13:39:18 +0530 Subject: [PATCH] http_client: fixed looping caused when disable_auto_redirect enabled Closes https://github.com/espressif/esp-idf/issues/10629 --- components/esp_http_client/esp_http_client.c | 13 +++++++++---- .../esp_http_client/include/esp_http_client.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 1fa6c47f37..d2b7f147f1 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -861,7 +861,12 @@ esp_err_t esp_http_client_set_redirection(esp_http_client_handle_t client) return ESP_ERR_INVALID_ARG; } ESP_LOGD(TAG, "Redirect to %s", client->location); - return esp_http_client_set_url(client, client->location); + esp_err_t err = esp_http_client_set_url(client, client->location); + if (err == ESP_OK) { + client->redirect_counter ++; + client->process_again = 1; // used only in the blocking mode (when esp_http_client_perform() is called) + } + return err; } static esp_err_t esp_http_check_response(esp_http_client_handle_t client) @@ -882,10 +887,10 @@ static esp_err_t esp_http_check_response(esp_http_client_handle_t client) if (client->disable_auto_redirect) { http_dispatch_event(client, HTTP_EVENT_REDIRECT, NULL, 0); } else { - ESP_ERROR_CHECK(esp_http_client_set_redirection(client)); + if (esp_http_client_set_redirection(client) != ESP_OK){ + return ESP_FAIL; + }; } - client->redirect_counter ++; - client->process_again = 1; break; case HttpStatus_Unauthorized: esp_http_client_add_auth(client); diff --git a/components/esp_http_client/include/esp_http_client.h b/components/esp_http_client/include/esp_http_client.h index 9309dd4ed2..be20c79c48 100644 --- a/components/esp_http_client/include/esp_http_client.h +++ b/components/esp_http_client/include/esp_http_client.h @@ -537,6 +537,7 @@ esp_http_client_transport_t esp_http_client_get_transport_type(esp_http_client_h * @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. + * When `disable_auto_redirect` is set, the client will not call this function but the event `HTTP_EVENT_REDIRECT` will be dispatched giving the user contol over the redirection event. * * @param[in] client The esp_http_client handle *