From db827733c3489097e64edea6ea555598fd25e9b5 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 12 Oct 2018 05:05:33 +0800 Subject: [PATCH] h1 ws client: produce CONNECTION --- lib/core/private.h | 2 +- lib/roles/http/client/client.c | 13 ++++++++----- lib/roles/ws/client-ws.c | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/core/private.h b/lib/core/private.h index a075880a2..3b1c3f2aa 100644 --- a/lib/core/private.h +++ b/lib/core/private.h @@ -1536,7 +1536,7 @@ lws_buflist_aware_consume(struct lws *wsi, struct lws_tokens *ebuf, int used, char * -lws_generate_client_ws_handshake(struct lws *wsi, char *p); +lws_generate_client_ws_handshake(struct lws *wsi, char *p, const char *conn1); int lws_client_ws_upgrade(struct lws *wsi, const char **cce); int diff --git a/lib/roles/http/client/client.c b/lib/roles/http/client/client.c index 46a5afe9a..42fc739b3 100644 --- a/lib/roles/http/client/client.c +++ b/lib/roles/http/client/client.c @@ -1067,9 +1067,6 @@ lws_generate_client_handshake(struct lws *wsi, char *pkt) p += sprintf(p, "Pragma: no-cache\x0d\x0a" "Cache-Control: no-cache\x0d\x0a"); - if (!wsi->client_pipeline) - p += sprintf(p, "connection: close\x0d\x0a"); - p += sprintf(p, "Host: %s\x0d\x0a", lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_HOST)); @@ -1085,9 +1082,15 @@ lws_generate_client_handshake(struct lws *wsi, char *pkt) _WSI_TOKEN_CLIENT_ORIGIN)); } #if defined(LWS_ROLE_WS) - if (wsi->do_ws) - p = lws_generate_client_ws_handshake(wsi, p); + if (wsi->do_ws) { + const char *conn1 = ""; + if (!wsi->client_pipeline) + conn1 = "close, "; + p = lws_generate_client_ws_handshake(wsi, p, conn1); + } else #endif + if (!wsi->client_pipeline) + p += sprintf(p, "connection: close\x0d\x0a"); /* give userland a chance to append, eg, cookies */ diff --git a/lib/roles/ws/client-ws.c b/lib/roles/ws/client-ws.c index 8c4c04b27..cc45da7b8 100644 --- a/lib/roles/ws/client-ws.c +++ b/lib/roles/ws/client-ws.c @@ -114,7 +114,7 @@ lws_ws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len) #endif char * -lws_generate_client_ws_handshake(struct lws *wsi, char *p) +lws_generate_client_ws_handshake(struct lws *wsi, char *p, const char *conn1) { char buf[128], hash[20], key_b64[40]; int n; @@ -136,8 +136,8 @@ lws_generate_client_ws_handshake(struct lws *wsi, char *p) lws_b64_encode_string(hash, 16, key_b64, sizeof(key_b64)); p += sprintf(p, "Upgrade: websocket\x0d\x0a" - "Connection: Upgrade\x0d\x0a" - "Sec-WebSocket-Key: "); + "Connection: %sUpgrade\x0d\x0a" + "Sec-WebSocket-Key: ", conn1); strcpy(p, key_b64); p += strlen(key_b64); p += sprintf(p, "\x0d\x0a");