Commit 5e91d919 authored by Sergey Lyubka's avatar Sergey Lyubka Committed by Cesanta Bot

Make mg_register_http_endpoint work for websocket

PUBLISHED_FROM=5bf5a007929b3b6275121f3cf949526e881fb482
parent 59348468
...@@ -4992,11 +4992,23 @@ void mg_http_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -4992,11 +4992,23 @@ void mg_http_handler(struct mg_connection *nc, int ev, void *ev_data) {
mg_ws_handler(nc, MG_EV_RECV, ev_data); mg_ws_handler(nc, MG_EV_RECV, ev_data);
} else if (nc->listener != NULL && } else if (nc->listener != NULL &&
(vec = mg_get_http_header(hm, "Sec-WebSocket-Key")) != NULL) { (vec = mg_get_http_header(hm, "Sec-WebSocket-Key")) != NULL) {
mg_event_handler_t handler;
/* This is a websocket request. Switch protocol handlers. */ /* This is a websocket request. Switch protocol handlers. */
mbuf_remove(io, req_len); mbuf_remove(io, req_len);
nc->proto_handler = mg_ws_handler; nc->proto_handler = mg_ws_handler;
nc->flags |= MG_F_IS_WEBSOCKET; nc->flags |= MG_F_IS_WEBSOCKET;
/*
* If we have a handler set up with mg_register_http_endpoint(),
* deliver subsequent websocket events to this handler after the
* protocol switch.
*/
handler = mg_http_get_endpoint_handler(nc->listener, &hm->uri);
if (handler != NULL) {
nc->handler = handler;
}
/* Send handshake */ /* Send handshake */
mg_call(nc, nc->handler, MG_EV_WEBSOCKET_HANDSHAKE_REQUEST, hm); mg_call(nc, nc->handler, MG_EV_WEBSOCKET_HANDSHAKE_REQUEST, hm);
if (!(nc->flags & MG_F_CLOSE_IMMEDIATELY)) { if (!(nc->flags & MG_F_CLOSE_IMMEDIATELY)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment