Merge branch 'feature/store_respnse_status_code_before_header_complete' into 'master'

feat(esp_http_client): Add HTTP_EVENT_ON_STATUS_CODE to notify early status code acquisition

Closes IDF-13452

See merge request espressif/esp-idf!40244
This commit is contained in:
Aditya Patwardhan
2025-07-10 12:35:10 +05:30
9 changed files with 22 additions and 0 deletions

View File

@@ -638,6 +638,8 @@ esp_err_t http_event_handle(esp_http_client_event_t *evt)
case HTTP_EVENT_REDIRECT:
ESP_LOGI(TAG, "HTTP_EVENT_REDIRECT");
break;
default:
break;
}
return ESP_OK;
}

View File

@@ -236,6 +236,15 @@ static int http_on_url(http_parser *parser, const char *at, size_t length)
static int http_on_status(http_parser *parser, const char *at, size_t length)
{
esp_http_client_handle_t client = parser->data;
ESP_LOGD(TAG, "http_on_status");
/* Store the status code in the response structure */
client->response->status_code = parser->status_code;
http_dispatch_event(client, HTTP_EVENT_ON_STATUS_CODE, &client->response->status_code, sizeof(int));
http_dispatch_event_to_event_loop(HTTP_EVENT_ON_STATUS_CODE, &client, sizeof(esp_http_client_handle_t));
return 0;
}

View File

@@ -40,6 +40,7 @@ typedef enum {
and will be deprecated in future versions esp-idf */
HTTP_EVENT_ON_HEADER, /*!< Occurs when receiving each header sent from the server */
HTTP_EVENT_ON_HEADERS_COMPLETE, /*!< Occurs when all headers are received on the client side */
HTTP_EVENT_ON_STATUS_CODE, /*!< Occurs when receiving the HTTP status code from the server */
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 */

View File

@@ -131,6 +131,7 @@ Expected data types for different HTTP Client events in the event loop are as fo
- HTTP_EVENT_HEADERS_SENT : ``esp_http_client_handle_t``
- HTTP_EVENT_ON_HEADER : ``esp_http_client_handle_t``
- HTTP_EVENT_ON_HEADERS_COMPLETE: ``esp_http_client_handle_t``
- HTTP_EVENT_ON_STATUS_CODE : ``esp_http_client_handle_t``
- HTTP_EVENT_ON_DATA : ``esp_http_client_on_data_t``
- HTTP_EVENT_ON_FINISH : ``esp_http_client_handle_t``
- HTTP_EVENT_DISCONNECTED : ``esp_http_client_handle_t``

View File

@@ -131,6 +131,7 @@ ESP HTTP 客户端诊断信息
- HTTP_EVENT_HEADERS_SENT : ``esp_http_client_handle_t``
- HTTP_EVENT_ON_HEADER : ``esp_http_client_handle_t``
- HTTP_EVENT_ON_HEADERS_COMPLETE: ``esp_http_client_handle_t``
- HTTP_EVENT_ON_STATUS_CODE : ``esp_http_client_handle_t``
- HTTP_EVENT_ON_DATA : ``esp_http_client_on_data_t``
- HTTP_EVENT_ON_FINISH : ``esp_http_client_handle_t``
- HTTP_EVENT_DISCONNECTED : ``esp_http_client_handle_t``

View File

@@ -117,6 +117,8 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
case HTTP_EVENT_REDIRECT:
ESP_LOGE(TAG, "HTTP_EVENT_REDIRECT: Not supported(%d)", esp_http_client_get_status_code(evt->client));
break;
default:
break;
}
return ESP_OK;
}

View File

@@ -139,6 +139,8 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
esp_http_client_set_header(evt->client, "Accept", "text/html");
esp_http_client_set_redirection(evt->client);
break;
default:
break;
}
return ESP_OK;
}

View File

@@ -87,6 +87,8 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
case HTTP_EVENT_REDIRECT:
ESP_LOGD(TAG, "HTTP_EVENT_REDIRECT");
break;
default:
break;
}
return ESP_OK;
}

View File

@@ -75,6 +75,8 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
case HTTP_EVENT_REDIRECT:
ESP_LOGD(TAG, "HTTP_EVENT_REDIRECT");
break;
default:
break;
}
return ESP_OK;
}