mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 15:44:34 +02:00
Merge branch 'feature/http_request_cancel' into 'master'
Cancel an HTTP request Closes IDFGH-8426 See merge request espressif/esp-idf!21171
This commit is contained in:
@@ -365,6 +365,29 @@ esp_err_t esp_http_client_get_password(esp_http_client_handle_t client, char **v
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t esp_http_client_cancel_request(esp_http_client_handle_t client)
|
||||||
|
{
|
||||||
|
if (client == NULL) {
|
||||||
|
ESP_LOGD(TAG, "Client handle is NULL");
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
if (client->state < HTTP_STATE_CONNECTED) {
|
||||||
|
ESP_LOGD(TAG, "Invalid State: %d", client->state);
|
||||||
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
if (esp_transport_close(client->transport) != 0) {
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t err = esp_http_client_connect(client);
|
||||||
|
// esp_http_client_connect() will return ESP_ERR_HTTP_CONNECTING in case of non-blocking mode and if the connection has not been established.
|
||||||
|
if (err == ESP_OK || (client->is_async && err == ESP_ERR_HTTP_CONNECTING)) {
|
||||||
|
client->response->data_process = client->response->content_length;
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
esp_err_t esp_http_client_set_password(esp_http_client_handle_t client, const char *password)
|
esp_err_t esp_http_client_set_password(esp_http_client_handle_t client, const char *password)
|
||||||
{
|
{
|
||||||
if (client == NULL) {
|
if (client == NULL) {
|
||||||
|
@@ -218,6 +218,18 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
|
|||||||
*/
|
*/
|
||||||
esp_err_t esp_http_client_perform(esp_http_client_handle_t client);
|
esp_err_t esp_http_client_perform(esp_http_client_handle_t client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Cancel an ongoing HTTP request. This API closes the current socket and opens a new socket with the same esp_http_client context.
|
||||||
|
*
|
||||||
|
* @param client The esp_http_client handle
|
||||||
|
* @return
|
||||||
|
* - ESP_OK on successful
|
||||||
|
* - ESP_FAIL on error
|
||||||
|
* - ESP_ERR_INVALID_ARG
|
||||||
|
* - ESP_ERR_INVALID_STATE
|
||||||
|
*/
|
||||||
|
esp_err_t esp_http_client_cancel_request(esp_http_client_handle_t client);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set URL for client, when performing this behavior, the options in the URL will replace the old ones
|
* @brief Set URL for client, when performing this behavior, the options in the URL will replace the old ones
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user