ignore leading spaces when checking for a suitable subprotocol

My Browsers send as Subprotocols e.g. chat, superchat, mySubprotocol (with spaces after the ,). Libwebsockets now checked if ' mySubprotocol' was equal to 'mySubprotocol' which failed. With this fix the leading space is ignored and uses 'mySubprotocol' for comparision.
This commit is contained in:
Tobias 2017-01-17 06:28:27 +08:00 committed by Andy Green
parent da6f03b423
commit 109d66c365

View file

@ -1021,7 +1021,7 @@ lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len)
struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
struct _lws_header_related hdr;
struct allocated_headers *ah;
int protocol_len, n = 0, hit;
int protocol_len, n = 0, hit, non_space_char_found = 0;
char protocol_list[128];
char protocol_name[64];
char *p;
@ -1195,8 +1195,17 @@ upgrade_ws:
while (*p && !hit) {
n = 0;
while (n < sizeof(protocol_name) - 1 && *p && *p !=',')
non_space_char_found = 0;
while (n < sizeof(protocol_name) - 1 && *p &&
*p != ',') {
// ignore leading spaces
if (!non_space_char_found && *p == ' ') {
n++;
continue;
}
non_space_char_found = 1;
protocol_name[n++] = *p++;
}
protocol_name[n] = '\0';
if (*p)
p++;