feat(http_server): improve websocket server handling

1. Adds post handshake callback
2. Removes requirement to handle HTTP_GET message in websocket handler

Closes https://github.com/espressif/esp-idf/issues/18215
This commit is contained in:
Ashish Sharma
2026-02-11 17:07:08 +08:00
parent 799c800494
commit 6f392e6fd6
7 changed files with 104 additions and 15 deletions

View File

@@ -75,6 +75,15 @@ The pre-handshake callback can be used for authentication, authorization, or oth
To use the WebSocket pre-handshake callback, you must enable :ref:`CONFIG_HTTPD_WS_PRE_HANDSHAKE_CB_SUPPORT` in your project configuration.
WebSocket Post-Handshake Callback
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Similar to the pre-handshake callback, the HTTP server component also provides a post-handshake callback for WebSocket endpoints. This callback is invoked after the WebSocket handshake is processed.
At this point the connection has been upgraded to WebSocket, and the server has responded with the WebSocket handshake response. This post handshake callback can be used for logging, sending initial messages, or other setup tasks.
To use the WebSocket post-handshake callback, you must enable :ref:`CONFIG_HTTPD_WS_POST_HANDSHAKE_CB_SUPPORT` in your project configuration.
.. code-block:: c
static esp_err_t ws_auth_handler(httpd_req_t *req)