mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-04 05:04:33 +02:00
Merge branch 'feature/add_http_event_error' into 'master'
esp_http_client: Support HTTP_EVENT_ERROR event Closes IDFGH-5557 See merge request espressif/esp-idf!14491
This commit is contained in:
@@ -994,6 +994,7 @@ int esp_http_client_read(esp_http_client_handle_t client, char *buffer, int len)
|
|||||||
ESP_LOG_LEVEL(sev, TAG, "esp_transport_read returned:%d and errno:%d ", rlen, errno);
|
ESP_LOG_LEVEL(sev, TAG, "esp_transport_read returned:%d and errno:%d ", rlen, errno);
|
||||||
}
|
}
|
||||||
if (rlen < 0 && ridx == 0 && !esp_http_client_is_complete_data_received(client)) {
|
if (rlen < 0 && ridx == 0 && !esp_http_client_is_complete_data_received(client)) {
|
||||||
|
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
} else {
|
} else {
|
||||||
return ridx;
|
return ridx;
|
||||||
@@ -1028,6 +1029,7 @@ esp_err_t esp_http_client_perform(esp_http_client_handle_t client)
|
|||||||
if (client->is_async && err == ESP_ERR_HTTP_CONNECTING) {
|
if (client->is_async && err == ESP_ERR_HTTP_CONNECTING) {
|
||||||
return ESP_ERR_HTTP_EAGAIN;
|
return ESP_ERR_HTTP_EAGAIN;
|
||||||
}
|
}
|
||||||
|
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
/* falls through */
|
/* falls through */
|
||||||
@@ -1036,6 +1038,7 @@ esp_err_t esp_http_client_perform(esp_http_client_handle_t client)
|
|||||||
if (client->is_async && errno == EAGAIN) {
|
if (client->is_async && errno == EAGAIN) {
|
||||||
return ESP_ERR_HTTP_EAGAIN;
|
return ESP_ERR_HTTP_EAGAIN;
|
||||||
}
|
}
|
||||||
|
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
/* falls through */
|
/* falls through */
|
||||||
@@ -1044,6 +1047,7 @@ esp_err_t esp_http_client_perform(esp_http_client_handle_t client)
|
|||||||
if (client->is_async && errno == EAGAIN) {
|
if (client->is_async && errno == EAGAIN) {
|
||||||
return ESP_ERR_HTTP_EAGAIN;
|
return ESP_ERR_HTTP_EAGAIN;
|
||||||
}
|
}
|
||||||
|
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
/* falls through */
|
/* falls through */
|
||||||
@@ -1055,14 +1059,17 @@ esp_err_t esp_http_client_perform(esp_http_client_handle_t client)
|
|||||||
if (esp_tls_get_and_clear_last_error(esp_transport_get_error_handle(client->transport), NULL, NULL) == ESP_ERR_ESP_TLS_TCP_CLOSED_FIN) {
|
if (esp_tls_get_and_clear_last_error(esp_transport_get_error_handle(client->transport), NULL, NULL) == ESP_ERR_ESP_TLS_TCP_CLOSED_FIN) {
|
||||||
ESP_LOGW(TAG, "Close connection due to FIN received");
|
ESP_LOGW(TAG, "Close connection due to FIN received");
|
||||||
esp_http_client_close(client);
|
esp_http_client_close(client);
|
||||||
|
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||||
return ESP_ERR_HTTP_CONNECTION_CLOSED;
|
return ESP_ERR_HTTP_CONNECTION_CLOSED;
|
||||||
}
|
}
|
||||||
|
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||||
return ESP_ERR_HTTP_FETCH_HEADER;
|
return ESP_ERR_HTTP_FETCH_HEADER;
|
||||||
}
|
}
|
||||||
/* falls through */
|
/* falls through */
|
||||||
case HTTP_STATE_RES_COMPLETE_HEADER:
|
case HTTP_STATE_RES_COMPLETE_HEADER:
|
||||||
if ((err = esp_http_check_response(client)) != ESP_OK) {
|
if ((err = esp_http_check_response(client)) != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Error response");
|
ESP_LOGE(TAG, "Error response");
|
||||||
|
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
while (client->response->is_chunked && !client->is_chunk_complete) {
|
while (client->response->is_chunked && !client->is_chunk_complete) {
|
||||||
@@ -1312,9 +1319,11 @@ esp_err_t esp_http_client_open(esp_http_client_handle_t client, int write_len)
|
|||||||
client->post_len = write_len;
|
client->post_len = write_len;
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
if ((err = esp_http_client_connect(client)) != ESP_OK) {
|
if ((err = esp_http_client_connect(client)) != ESP_OK) {
|
||||||
|
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
if ((err = esp_http_client_request_send(client, write_len)) != ESP_OK) {
|
if ((err = esp_http_client_request_send(client, write_len)) != ESP_OK) {
|
||||||
|
http_dispatch_event(client, HTTP_EVENT_ERROR, esp_transport_get_error_handle(client->transport), 0);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
Reference in New Issue
Block a user