From f1ad1c6b1a47da8c99185c4f62488d696410ec2d Mon Sep 17 00:00:00 2001 From: Joe Littlejohn Date: Wed, 7 Mar 2018 20:22:47 +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 15bfce55..5a8228d8 100644 --- a/lib/client/client.c +++ b/lib/client/client.c @@ -759,12 +759,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); @@ -772,6 +766,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");