mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00
more robust subprotocol selection handling with test
This commit is contained in:
parent
abc3a7859e
commit
191098c95f
2 changed files with 17 additions and 6 deletions
19
lib/client.c
19
lib/client.c
|
@ -589,11 +589,22 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context,
|
|||
wsi->protocol = &context->protocols[n];
|
||||
break;
|
||||
} else {
|
||||
char* sp = strstr(context->protocols[n].name, p);
|
||||
if (sp && (sp[len] == ',' || sp[len] == '\0')) {
|
||||
wsi->protocol = &context->protocols[n];
|
||||
break;
|
||||
int found = 0;
|
||||
const char* nameptr = context->protocols[n].name;
|
||||
char* sp = strstr(nameptr, p);
|
||||
while (sp && !found) {
|
||||
if ((sp[len] == ',' || sp[len] == '\0')
|
||||
&& (sp == nameptr
|
||||
|| (sp > nameptr
|
||||
&& (sp[-1] == ',' || sp[-1] == ' ')))) {
|
||||
wsi->protocol = &context->protocols[n];
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
sp = strstr(sp + 1, p);
|
||||
}
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
|
|
|
@ -221,13 +221,13 @@ callback_lws_mirror(struct libwebsocket_context *context,
|
|||
|
||||
static struct libwebsocket_protocols protocols[] = {
|
||||
{
|
||||
"dumb-increment-protocol,fake-nonexistant-protocol",
|
||||
"dumb-increment-protocol-nonexistant,dumb-increment-protocol,fake-nonexistant-protocol",
|
||||
callback_dumb_increment,
|
||||
0,
|
||||
20,
|
||||
},
|
||||
{
|
||||
"fake-nonexistant-protocol,lws-mirror-protocol",
|
||||
"lws-mirror-protocol-nonexistant,fake-nonexistant-protocol,lws-mirror-protocol",
|
||||
callback_lws_mirror,
|
||||
0,
|
||||
128,
|
||||
|
|
Loading…
Add table
Reference in a new issue