feat(esp_https_server): adds support for user callback on handshake failure

Closes https://github.com/espressif/esp-idf/issues/18053
This commit is contained in:
Ashish Sharma
2026-01-07 16:04:03 +08:00
parent dad6e2b020
commit 22d7c20b31
3 changed files with 36 additions and 2 deletions
@@ -39,11 +39,12 @@ typedef enum {
/**
* @brief Indicates the state at which the user callback is executed,
* i.e at session creation or session close
* i.e at session creation, session close, or session error
*/
typedef enum {
HTTPD_SSL_USER_CB_SESS_CREATE,
HTTPD_SSL_USER_CB_SESS_CLOSE
HTTPD_SSL_USER_CB_SESS_CLOSE,
HTTPD_SSL_USER_CB_SESS_ERROR
} httpd_ssl_user_cb_state_t;
typedef esp_tls_handshake_callback esp_https_server_cert_select_cb;
@@ -234,6 +234,13 @@ fail:
last_error.last_error = esp_tls_get_and_clear_last_error(error_handle, &last_error.esp_tls_error_code, &last_error.esp_tls_flags);
http_dispatch_event_to_event_loop(HTTPS_SERVER_EVENT_ERROR, &last_error, sizeof(last_error));
}
// Call user callback if configured, allowing user to log failures
if (global_ctx->user_cb) {
esp_https_server_user_cb_arg_t user_cb_data = {0};
user_cb_data.user_cb_state = HTTPD_SSL_USER_CB_SESS_ERROR;
user_cb_data.tls = tls;
(global_ctx->user_cb)((void *)&user_cb_data);
}
esp_tls_server_session_delete(tls);
}
return ESP_FAIL;