mirror of
https://github.com/espressif/esp-idf.git
synced 2026-08-13 04:42:01 +03:00
feat(esp_http_server): Added pre handshake callback for websocket
1. If the user wants authenticate the request, then user needs to do this before upgrading the protocol to websocket. 2. To achieve this, added pre_handshake_callack, which will execute before handshake, i.e. before switching protocol.
This commit is contained in:
@@ -166,6 +166,9 @@ esp_err_t httpd_register_uri_handler(httpd_handle_t handle,
|
||||
hd->hd_calls[i]->method = uri_handler->method;
|
||||
hd->hd_calls[i]->handler = uri_handler->handler;
|
||||
hd->hd_calls[i]->user_ctx = uri_handler->user_ctx;
|
||||
#ifdef CONFIG_HTTPD_WS_PRE_HANDSHAKE_CB_SUPPORT
|
||||
hd->hd_calls[i]->ws_pre_handshake_cb = uri_handler->ws_pre_handshake_cb;
|
||||
#endif
|
||||
#ifdef CONFIG_HTTPD_WS_SUPPORT
|
||||
hd->hd_calls[i]->is_websocket = uri_handler->is_websocket;
|
||||
hd->hd_calls[i]->handle_ws_control_frames = uri_handler->handle_ws_control_frames;
|
||||
@@ -320,6 +323,13 @@ esp_err_t httpd_uri(struct httpd_data *hd)
|
||||
#ifdef CONFIG_HTTPD_WS_SUPPORT
|
||||
struct httpd_req_aux *aux = req->aux;
|
||||
if (uri->is_websocket && aux->ws_handshake_detect && uri->method == HTTP_GET) {
|
||||
#ifdef CONFIG_HTTPD_WS_PRE_HANDSHAKE_CB_SUPPORT
|
||||
if (uri->ws_pre_handshake_cb && uri->ws_pre_handshake_cb(req) != ESP_OK) {
|
||||
ESP_LOGW(TAG, LOG_FMT("ws_pre_handshake_cb failed"));
|
||||
return ESP_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
ESP_LOGD(TAG, LOG_FMT("Responding WS handshake to sock %d"), aux->sd->fd);
|
||||
esp_err_t ret = httpd_ws_respond_server_handshake(&hd->hd_req, uri->supported_subprotocol);
|
||||
if (ret != ESP_OK) {
|
||||
|
||||
Reference in New Issue
Block a user