diff --git a/other/websocket.c b/other/websocket.c index c365409..113256d 100644 --- a/other/websocket.c +++ b/other/websocket.c @@ -475,12 +475,17 @@ int parse_handshake(ws_ctx_t *ws_ctx, char *handshake) { strncpy(headers->connection, start, end-start); headers->connection[end-start] = '\0'; + //RFC 6455 11.3.4 - Sec-WebSocket-Protocol MAY appear multiple times + //in a request. Or it may not appear at all. start = strstr(handshake, "\r\nSec-WebSocket-Protocol: "); - if (!start) { return 0; } - start += 26; - end = strstr(start, "\r\n"); - strncpy(headers->protocols, start, end-start); - headers->protocols[end-start] = '\0'; + if (start) { + start += 26; + end = strstr(start, "\r\n"); + strncpy(headers->protocols, start, end-start); + headers->protocols[end-start] = '\0'; + } else { + headers->protocols[0] = '\0'; + } } else { // Hixie 75 or 76 ws_ctx->hybi = 0;