Merge branch 'contrib/github_pr_17799_v6.0' into 'release/v6.0'

feat(esp_http_server): Make HTTP(S)_SERVER_EVENT events optional (GitHub PR) (v6.0)

See merge request espressif/esp-idf!48352
This commit is contained in:
Mahavir Jain
2026-07-02 15:42:45 +05:30
8 changed files with 52 additions and 1 deletions
+8
View File
@@ -66,8 +66,16 @@ menu "HTTP Server"
this only if your application can tolerate the call blocking and wants
guaranteed delivery instead of a fast-fail.
config HTTPD_ENABLE_EVENTS
bool "Enable ESP_HTTP_SERVER_EVENT"
default y
help
This enables the ESP_HTTP_SERVER_EVENT event type. Generating these eventes adds some overhead.
If you are not using this event type, you can disable it to save some memory and add performance.
config HTTPD_SERVER_EVENT_POST_TIMEOUT
int "Time in millisecond to wait for posting event"
depends on HTTPD_ENABLE_EVENTS
default 2000
help
This config option helps in setting the time in millisecond to wait for event to be posted to the
@@ -23,7 +23,9 @@ extern "C" {
#define ESP_HTTPD_DEF_CTRL_PORT (32768) /*!< HTTP Server control socket port*/
#if CONFIG_HTTPD_ENABLE_EVENTS || __DOXYGEN_
ESP_EVENT_DECLARE_BASE(ESP_HTTP_SERVER_EVENT);
#endif // CONFIG_HTTPD_ENABLE_EVENTS || __DOXYGEN_
/**
* @brief HTTP Server events id
@@ -591,6 +591,8 @@ esp_err_t httpd_sess_close_lru_direct(struct httpd_data *hd);
* @}
*/
#ifdef CONFIG_HTTPD_ENABLE_EVENTS
#if CONFIG_HTTPD_SERVER_EVENT_POST_TIMEOUT == -1
#define ESP_HTTP_SERVER_EVENT_POST_TIMEOUT portMAX_DELAY
#else
@@ -603,6 +605,18 @@ esp_err_t httpd_sess_close_lru_direct(struct httpd_data *hd);
*/
void esp_http_server_dispatch_event(int32_t event_id, const void* event_data, size_t event_data_size);
#else // CONFIG_HTTPD_ENABLE_EVENTS
static inline void esp_http_server_dispatch_event(int32_t event_id, const void* event_data, size_t event_data_size)
{
// Events disabled, do nothing
(void) event_id;
(void) event_data;
(void) event_data_size;
}
#endif // CONFIG_HTTPD_ENABLE_EVENTS
esp_err_t httpd_crypto_sha1(const uint8_t *data, size_t data_len, uint8_t *hash);
#ifdef __cplusplus
}
#endif
@@ -38,6 +38,7 @@ typedef struct {
static const char *TAG = "httpd";
#ifdef CONFIG_HTTPD_ENABLE_EVENTS
ESP_EVENT_DEFINE_BASE(ESP_HTTP_SERVER_EVENT);
void esp_http_server_dispatch_event(int32_t event_id, const void* event_data, size_t event_data_size)
@@ -47,6 +48,7 @@ void esp_http_server_dispatch_event(int32_t event_id, const void* event_data, si
ESP_LOGE(TAG, "Failed to post esp_http_server event: %s", esp_err_to_name(err));
}
}
#endif // CONFIG_HTTPD_ENABLE_EVENTS
static esp_err_t httpd_accept_conn(struct httpd_data *hd)
{
+10
View File
@@ -6,8 +6,18 @@ menu "ESP HTTPS server"
help
Enable ESP HTTPS server component
config ESP_HTTPS_SERVER_EVENTS
bool "Enable ESP_HTTPS_SERVER_EVENT event type"
depends on ESP_HTTPS_SERVER_ENABLE
default y
help
This enables the ESP_HTTPS_SERVER_EVENT event type. Generating these eventes adds some overhead.
If you are not using this event type, you can disable it to save some memory.
config ESP_HTTPS_SERVER_EVENT_POST_TIMEOUT
int "Time in millisecond to wait for posting event"
depends on (ESP_HTTPS_SERVER_ENABLE && ESP_HTTPS_SERVER_EVENTS)
default 2000
help
This config option helps in setting the time in millisecond to wait for event to be posted to the
@@ -18,7 +18,9 @@
extern "C" {
#endif
#if CONFIG_ESP_HTTPS_SERVER_EVENTS || __DOXYGEN__
ESP_EVENT_DECLARE_BASE(ESP_HTTPS_SERVER_EVENT);
#endif // CONFIG_ESP_HTTPS_SERVER_EVENTS || __DOXYGEN__
typedef enum {
HTTPS_SERVER_EVENT_ERROR = 0, /*!< This event occurs when there are any errors during execution */
+10 -1
View File
@@ -23,6 +23,7 @@ typedef struct httpd_ssl_transport_ctx {
httpd_ssl_ctx_t *global_ctx;
} httpd_ssl_transport_ctx_t;
#ifdef CONFIG_ESP_HTTPS_SERVER_EVENTS
ESP_EVENT_DEFINE_BASE(ESP_HTTPS_SERVER_EVENT);
#if CONFIG_ESP_HTTPS_SERVER_EVENT_POST_TIMEOUT == -1
@@ -31,7 +32,6 @@ ESP_EVENT_DEFINE_BASE(ESP_HTTPS_SERVER_EVENT);
#define ESP_HTTPS_SERVER_EVENT_POST_TIMEOUT pdMS_TO_TICKS(CONFIG_ESP_HTTPS_SERVER_EVENT_POST_TIMEOUT)
#endif
static void http_dispatch_event_to_event_loop(int32_t event_id, const void* event_data, size_t event_data_size)
{
esp_err_t err = esp_event_post(ESP_HTTPS_SERVER_EVENT, event_id, event_data, event_data_size, ESP_HTTPS_SERVER_EVENT_POST_TIMEOUT);
@@ -39,6 +39,15 @@ static void http_dispatch_event_to_event_loop(int32_t event_id, const void* even
ESP_LOGE(TAG, "Failed to post http_client event: %"PRId32", error: %s", event_id, esp_err_to_name(err));
}
}
#else // CONFIG_ESP_HTTPS_SERVER_EVENTS
static void http_dispatch_event_to_event_loop(int32_t event_id, const void* event_data, size_t event_data_size)
{
// Events disabled, do nothing
(void) event_id;
(void) event_data;
(void) event_data_size;
}
#endif // CONFIG_ESP_HTTPS_SERVER_EVENTS
/**
* SSL socket close handler
@@ -37,6 +37,7 @@
static const char *TAG = "example";
#ifdef CONFIG_ESP_HTTPS_SERVER_EVENTS
/* Event handler for catching system events */
static void event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
@@ -48,6 +49,7 @@ static void event_handler(void* arg, esp_event_base_t event_base,
}
}
}
#endif // CONFIG_ESP_HTTPS_SERVER_EVENTS
/* An HTTP GET handler */
static esp_err_t root_get_handler(httpd_req_t *req)
@@ -295,7 +297,9 @@ void app_main(void)
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_DISCONNECTED, &disconnect_handler, &server));
#endif // CONFIG_EXAMPLE_CONNECT_ETHERNET
#endif // !CONFIG_IDF_TARGET_LINUX
#ifdef CONFIG_ESP_HTTPS_SERVER_EVENTS
ESP_ERROR_CHECK(esp_event_handler_register(ESP_HTTPS_SERVER_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
#endif // CONFIG_ESP_HTTPS_SERVER_EVENTS
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
* Read "Establishing Wi-Fi or Ethernet Connection" section in