Add extra headers param to mg_ws_upgrade()

This commit is contained in:
cpq committed 2021-01-16 22:48:43 +00:00
1 parent 72d3a49352
commit ae6fd6aa35
8 files changed
+49 -28

No files matched your search

+4 -4
View File
@@ -18,7 +18,7 @@ static const char *s_listen_on = "http://localhost:8000";
static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
mg_ws_upgrade(c, hm);
mg_ws_upgrade(c, hm, NULL);
} else if (ev == MG_EV_WS_MSG) {
// Got websocket frame. Received data is wm->data. Echo it back!
struct mg_ws_message *wm = (struct mg_ws_message *) ev_data;
@@ -42,9 +42,9 @@ static void timer_fn(void *arg) {
}
int main(void) {
struct mg_mgr mgr; // Event manager
struct mg_timer t1; // Timer
mg_mgr_init(&mgr); // Initialise event manager
struct mg_mgr mgr; // Event manager
struct mg_timer t1; // Timer
mg_mgr_init(&mgr); // Initialise event manager
mg_timer_init(&t1, 300, MG_TIMER_REPEAT, timer_fn, &mgr); // Init timer
mg_http_listen(&mgr, s_listen_on, fn, NULL); // Create HTTP listener
for (;;) mg_mgr_poll(&mgr, 1000); // Infinite event loop
+1 -1
View File
@@ -21,7 +21,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (mg_http_match_uri(hm, "/websocket")) {
// Upgrade to websocket. From now on, a connection is a full-duplex
// Websocket connection, which will receive MG_EV_WS_MSG events.
mg_ws_upgrade(c, hm);
mg_ws_upgrade(c, hm, NULL);
} else if (mg_http_match_uri(hm, "/rest")) {
// Serve REST response
mg_http_reply(c, 200, "", "{\"result\": %d}\n", 123);