diff --git a/components/esp_http_server/src/httpd_parse.c b/components/esp_http_server/src/httpd_parse.c index b520c871b1..62244f9f9f 100644 --- a/components/esp_http_server/src/httpd_parse.c +++ b/components/esp_http_server/src/httpd_parse.c @@ -774,9 +774,16 @@ esp_err_t httpd_req_new(struct httpd_data *hd, struct sock_db *sd) ESP_LOGD(TAG, LOG_FMT("Received PONG frame")); } - /* Call handler if it's a non-control frame (or if handler requests control frames, as well) */ + /* Call handler if it's a non-control frame, a PONG frame, + * or if handler requests control frames as well. + * PONG must be dispatched so that: + * 1. User code that sends PINGs can track responses (heartbeat) + * 2. The PONG frame bytes are consumed from the socket via + * httpd_ws_recv_frame(), preventing TCP stream misalignment */ if (ret == ESP_OK && - (ra->ws_type < HTTPD_WS_TYPE_CLOSE || sd->ws_control_frames)) { + (ra->ws_type < HTTPD_WS_TYPE_CLOSE || + ra->ws_type == HTTPD_WS_TYPE_PONG || + sd->ws_control_frames)) { ret = sd->ws_handler(r); }