diff --git a/lib/client.c b/lib/client.c index 9a00dc68..06d1a50d 100755 --- a/lib/client.c +++ b/lib/client.c @@ -565,12 +565,12 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context, } while (*pc && *pc != ',') pc++; - while (*pc && *pc != ' ') + while (*pc && *pc == ' ') pc++; } if (!okay) { - lwsl_err("lws_client_int_s_hs: got bad protocol %s\n", p); + lwsl_err("lws_client_int_s_hs: got bad protocol '%s'\n", p); goto bail2; } @@ -588,7 +588,7 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context, } if (wsi->protocol == NULL) { - lwsl_err("lws_client_int_s_hs: fail protocol %s\n", p); + lwsl_err("lws_client_int_s_hs: fail protocol '%s'\n", p); goto bail2; } diff --git a/lib/server-handshake.c b/lib/server-handshake.c index 4c0fa738..8a150540 100644 --- a/lib/server-handshake.c +++ b/lib/server-handshake.c @@ -217,10 +217,7 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi) if (lws_hdr_total_length(wsi, WSI_TOKEN_PROTOCOL)) { LWS_CPYAPP(p, "\x0d\x0aSec-WebSocket-Protocol: "); - n = lws_hdr_copy(wsi, p, 128, WSI_TOKEN_PROTOCOL); - if (n < 0) - goto bail; - p += n; + LWS_CPYAPP(p, wsi->protocol->name); } #ifndef LWS_NO_EXTENSIONS diff --git a/lib/server.c b/lib/server.c index f02e5dee..88a1920c 100644 --- a/lib/server.c +++ b/lib/server.c @@ -428,9 +428,9 @@ upgrade_h2c: "HTTP/1.1 101 Switching Protocols\x0d\x0a" "Connection: Upgrade\x0d\x0a" "Upgrade: h2c\x0d\x0a\x0d\x0a"); - n = lws_issue_raw(wsi, (unsigned char *)protocol_list, - strlen(protocol_list)); - if (n != strlen(protocol_list)) { + n = lws_issue_raw(wsi, (unsigned char *)wsi->protocol->name, + strlen(wsi->protocol->name)); + if (n != strlen(wsi->protocol->name)) { lwsl_debug("http2 switch: ERROR writing to socket\n"); return 1; } @@ -471,6 +471,8 @@ upgrade_ws: protocol_name[n] = '\0'; if (*p) p++; + while (*p == ' ') + p++; lwsl_info("checking %s\n", protocol_name);