From 2627148523cdc83d07eb6aa8bdae36860922d57b Mon Sep 17 00:00:00 2001 From: Andy Green Date: Wed, 21 Oct 2015 08:16:34 +0800 Subject: [PATCH] keepalive fix flow now forced closed removed Since 0d89f3cbed69a86251e6ed791c57e99a7f59c8d9 added recently, http1.1 keepalive tries to actually keep alive. Some updates are needed to keepalive flow to solve problems coming from changes that were hidden until now by keepalive basically closing until recently. It's not very noticable since clients will retry as close is the default 1.0 behaviour... anyway this lets me do wget http://localhost:7681/test.html http://localhost:7681/test.html using keepalive correctly on the test server. Signed-off-by: Andy Green --- lib/handshake.c | 25 ++++++------------------- lib/server.c | 13 ++++++++++++- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/handshake.c b/lib/handshake.c index 856297db..bf01f514 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -200,27 +200,14 @@ http_complete: lwsl_debug("libwebsocket_read: http_complete\n"); /* Did the client want to keep the HTTP connection going? */ + if (lws_http_transaction_completed(wsi)) + goto bail; - if (wsi->u.http.connection_type == HTTP_CONNECTION_KEEP_ALIVE) { - lwsl_debug("libwebsocket_read: keep-alive\n"); - wsi->state = WSI_STATE_HTTP; - wsi->mode = LWS_CONNMODE_HTTP_SERVING; + /* If we have more data, loop back around: */ + if (len) + goto http_new; - /* He asked for it to stay alive indefinitely */ - libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); - - if (lws_allocate_header_table(wsi)) - goto bail; - - /* If we're (re)starting on headers, need other implied init */ - wsi->u.hdr.ues = URIES_IDLE; - - /* If we have more data, loop back around: */ - if (len) - goto http_new; - - return 0; - } + return 0; bail: lwsl_debug("closing connection at libwebsocket_read bail:\n"); diff --git a/lib/server.c b/lib/server.c index b4a67e49..b98bf1e9 100644 --- a/lib/server.c +++ b/lib/server.c @@ -649,8 +649,19 @@ int lws_http_transaction_completed(struct libwebsocket *wsi) /* otherwise set ourselves up ready to go again */ wsi->state = WSI_STATE_HTTP; + wsi->mode = LWS_CONNMODE_HTTP_SERVING; + wsi->u.http.content_length = 0; + + /* He asked for it to stay alive indefinitely */ + libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); + + if (lws_allocate_header_table(wsi)) + return 1; + + /* If we're (re)starting on headers, need other implied init */ + wsi->u.hdr.ues = URIES_IDLE; - lwsl_info("%s: await new transaction\n", __func__); + lwsl_info("%s: keep-alive await new transaction\n", __func__); return 0; }