From b3e3c05d6781caa5db54fc9913772ddc1af2e045 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 23 Jan 2024 09:48:35 +0100 Subject: [PATCH] client: don't send stray EOF chunk on connection timeout Ensure that any kind of chunk data is only sent when the client connection is in the body data state in order to avoid sending superfluous `0\r\n\r\n` chunks on closing idle connections. Signed-off-by: Jo-Philipp Wich --- client.c | 4 +--- utils.c | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/client.c b/client.c index c037cc7..a987867 100644 --- a/client.c +++ b/client.c @@ -158,10 +158,8 @@ uh_client_error(struct client *cl, int code, const char *summary, const char *fm * interpreted as part of the next request. The alternative * would be to read and discard the request body here. */ - if (r->transfer_chunked || r->content_length > 0) { - cl->state = CLIENT_STATE_CLOSE; + if (r->transfer_chunked || r->content_length > 0) cl->request.connection_close = true; - } uh_request_done(cl); } diff --git a/utils.c b/utils.c index 6502d94..5304c2a 100644 --- a/utils.c +++ b/utils.c @@ -56,7 +56,7 @@ void uh_chunk_vprintf(struct client *cl, const char *format, va_list arg) va_list arg2; int len; - if (cl->state == CLIENT_STATE_CLEANUP) + if (cl->state != CLIENT_STATE_DATA) return; uloop_timeout_set(&cl->timeout, conf.network_timeout * 1000); @@ -91,7 +91,7 @@ void uh_chunk_eof(struct client *cl) if (!uh_use_chunked(cl)) return; - if (cl->state == CLIENT_STATE_CLEANUP) + if (cl->state != CLIENT_STATE_DATA) return; ustream_printf(cl->us, "0\r\n\r\n"); -- 2.30.2