From 0850231a09b65dc787d63fe0701c8bef2edbfde2 Mon Sep 17 00:00:00 2001 From: kzhdev Date: Thu, 4 Apr 2019 20:04:25 -0500 Subject: [PATCH] ws: client: if server sends no subprotocol prefer any existing protocol --- lib/roles/ws/client-ws.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/roles/ws/client-ws.c b/lib/roles/ws/client-ws.c index cabca0fb7..18b225595 100644 --- a/lib/roles/ws/client-ws.c +++ b/lib/roles/ws/client-ws.c @@ -305,9 +305,17 @@ bad_conn_format: if (!len) { lwsl_info("%s: WSI_TOKEN_PROTOCOL is null\n", __func__); /* - * no protocol name to work from, + * no protocol name to work from, if we don't already have one * default to first protocol */ + + if (wsi->protocol) { + p = (char *)wsi->protocol->name; + goto identify_protocol; + } + + /* no choice but to use the default protocol */ + n = 0; wsi->protocol = &wsi->vhost->protocols[0]; goto check_extensions; @@ -334,6 +342,8 @@ bad_conn_format: goto bail2; } +identify_protocol: + #if defined(LWS_WITH_HTTP_PROXY) lws_strncpy(wsi->ws->actual_protocol, p, sizeof(wsi->ws->actual_protocol));