From fad43ff8e9b70809d752044950236cd1e23b2a3e Mon Sep 17 00:00:00 2001 From: Joe Littlejohn Date: Wed, 7 Mar 2018 20:23:46 +0800 Subject: [PATCH] Check status before checking for Sec-WebSocket-Accept If the server rejects the attempt to establish a connection by returning a response status other than 101, then it will not include the Sec-WebSocket-Accept header. We need to check for 101 status (and return an appropriate error message) before looking for the accept header. See #1200 --- lib/client/client.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/client/client.c b/lib/client/client.c index 76d75819a..adb104546 100644 --- a/lib/client/client.c +++ b/lib/client/client.c @@ -728,12 +728,6 @@ lws_client_interpret_server_handshake(struct lws *wsi) return 0; } - if (lws_hdr_total_length(wsi, WSI_TOKEN_ACCEPT) == 0) { - lwsl_info("no ACCEPT\n"); - cce = "HS: ACCEPT missing"; - goto bail3; - } - if (p && strncmp(p, "101", 3)) { lwsl_warn( "lws_client_handshake: got bad HTTP response '%s'\n", p); @@ -741,6 +735,12 @@ lws_client_interpret_server_handshake(struct lws *wsi) goto bail3; } + if (lws_hdr_total_length(wsi, WSI_TOKEN_ACCEPT) == 0) { + lwsl_info("no ACCEPT\n"); + cce = "HS: ACCEPT missing"; + goto bail3; + } + p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_UPGRADE); if (!p) { lwsl_info("no UPGRADE\n");