From 73e0c62b4c8dc7eaed202deb2c867d69cabb2a4f Mon Sep 17 00:00:00 2001 From: Steve English Date: Tue, 28 Aug 2012 14:13:25 +0100 Subject: [PATCH] Don't require Sec-WebSocket-Protocol header. RFC 6455 11.3.4 says this header MAY be used, so allow connections without it. --- other/websocket.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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;