client: don't send stray EOF chunk on connection timeout
authorJo-Philipp Wich <jo@mein.io>
Tue, 23 Jan 2024 08:48:35 +0000 (09:48 +0100)
committerJo-Philipp Wich <jo@mein.io>
Tue, 23 Jan 2024 08:48:35 +0000 (09:48 +0100)
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 <jo@mein.io>
client.c
utils.c

index c037cc79874855999fb849c03e064a7f6a99072b..a987867c14304ee0d0ceaac2956086c908b6bb12 100644 (file)
--- 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 6502d948f7d8c9766fac463d87495dbbd53401fa..5304c2acd3ae5579ffaca4b2a0147ed73f186487 100644 (file)
--- 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");