esp_http_client: Added event for HTTP redirect
- Allows users to manually intercept and process the HTTP redirection when disable_auto_redirect (from the esp_http_client handle) is set to true Closes https://github.com/espressif/esp-idf/issues/8029
This commit is contained in:
@@ -461,6 +461,9 @@ esp_err_t http_event_handle(esp_http_client_event_t *evt)
|
||||
case HTTP_EVENT_DISCONNECTED:
|
||||
ESP_LOGI(TAG, "HTTP_EVENT_DISCONNECTED");
|
||||
break;
|
||||
case HTTP_EVENT_REDIRECT:
|
||||
ESP_LOGI(TAG, "HTTP_EVENT_REDIRECT");
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -787,7 +787,7 @@ static esp_err_t esp_http_check_response(esp_http_client_handle_t client)
|
||||
if (client->response->status_code >= HttpStatus_Ok && client->response->status_code < HttpStatus_MultipleChoices) {
|
||||
return ESP_OK;
|
||||
}
|
||||
if (client->redirect_counter >= client->max_redirection_count || client->disable_auto_redirect) {
|
||||
if (client->redirect_counter >= client->max_redirection_count) {
|
||||
ESP_LOGE(TAG, "Error, reach max_redirection_count count=%d", client->redirect_counter);
|
||||
return ESP_ERR_HTTP_MAX_REDIRECT;
|
||||
}
|
||||
@@ -795,6 +795,9 @@ static esp_err_t esp_http_check_response(esp_http_client_handle_t client)
|
||||
case HttpStatus_MovedPermanently:
|
||||
case HttpStatus_Found:
|
||||
case HttpStatus_TemporaryRedirect:
|
||||
if (client->disable_auto_redirect) {
|
||||
http_dispatch_event(client, HTTP_EVENT_REDIRECT, NULL, 0);
|
||||
}
|
||||
esp_http_client_set_redirection(client);
|
||||
client->redirect_counter ++;
|
||||
client->process_again = 1;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -35,6 +35,7 @@ typedef enum {
|
||||
HTTP_EVENT_ON_DATA, /*!< Occurs when receiving data from the server, possibly multiple portions of the packet */
|
||||
HTTP_EVENT_ON_FINISH, /*!< Occurs when finish a HTTP session */
|
||||
HTTP_EVENT_DISCONNECTED, /*!< The connection has been disconnected */
|
||||
HTTP_EVENT_REDIRECT, /*!< Intercepting HTTP redirects to handle them manually */
|
||||
} esp_http_client_event_id_t;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user