Make ws_upgrade() respond with error if request is not and upgrade

This commit is contained in:
Sergey Lyubka committed 2021-08-03 23:37:50 +01:00
1 parent a36050ab4b
commit 9b18a6350a
3 files changed
+43 -32

No files matched your search

+5 -2
View File
@@ -217,13 +217,16 @@ void mg_ws_upgrade(struct mg_connection *c, struct mg_http_message *hm,
const char *fmt, ...) {
struct mg_str *wskey = mg_http_get_header(hm, "Sec-WebSocket-Key");
c->pfn = mg_ws_cb;
if (wskey != NULL) {
if (wskey == NULL) {
mg_http_reply(c, 426, "", "WS upgrade expected\n");
c->is_draining = 1;
} else {
va_list ap;
va_start(ap, fmt);
ws_handshake(c, wskey->ptr, wskey->len, fmt, ap);
va_end(ap);
c->is_websocket = 1;
}
c->is_websocket = 1;
}
size_t mg_ws_wrap(struct mg_connection *c, size_t len, int op) {