example: Identify the callback whether is hanshake or frame-receive by req->method

Now the uri handler gets called immediately after the handshake. In the handler we can identify that this was the handshake by checking req->method as it is still a GET from the first part of the handshake the client has sent. On a normal websocket-frame-receive (when normally a websocket uriHandler gets called) this field is set to 0
Closes https://github.com/espressif/esp-idf/issues/6597
This commit is contained in:
yuanjm 2021-03-05 15:33:02 +08:00 committed by bot
parent b3612b73d6
commit a1d5cfc260
2 changed files with 8 additions and 0 deletions

View File

@ -67,6 +67,10 @@ static esp_err_t trigger_async_send(httpd_handle_t handle, httpd_req_t *req)
*/
static esp_err_t echo_handler(httpd_req_t *req)
{
if (req->method == HTTP_GET) {
ESP_LOGI(TAG, "Handshake done, the new connection was opened");
return ESP_OK;
}
httpd_ws_frame_t ws_pkt;
memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t));
ws_pkt.type = HTTPD_WS_TYPE_TEXT;

View File

@ -33,6 +33,10 @@ static const size_t max_clients = 4;
static esp_err_t ws_handler(httpd_req_t *req)
{
if (req->method == HTTP_GET) {
ESP_LOGI(TAG, "Handshake done, the new connection was opened");
return ESP_OK;
}
httpd_ws_frame_t ws_pkt;
memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t));