commit 496900010b80b30eacbf341a95e0ef9b18e055a8 parent be6faace006bef08d2bd24d17471090daaee40fd Author: Evgeny Grin (Karlson2k) <k2k@narod.ru> Date: Wed, 18 Aug 2021 12:43:11 +0300 RFC compliance: use chunked even for non-Keep-Alive HTTP/1.1 clients Diffstat:
| M | src/include/microhttpd.h | | | 2 | +- |
| M | src/microhttpd/connection.c | | | 13 | ++++++++----- |
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -131,7 +131,7 @@ typedef intptr_t ssize_t; * they are parsed as decimal numbers. * Example: 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00097305 +#define MHD_VERSION 0x00097306 #ifdef __has_attribute diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -1630,19 +1630,22 @@ setup_reply_properties (struct MHD_Connection *connection) else if (0 != (r->flags & (MHD_RF_HTTP_VERSION_1_0_ONLY | MHD_RF_HTTP_VERSION_1_0_RESPONSE))) use_chunked = false; - /* TODO: Use chunked for HTTP/1.1 non-Keep-Alive */ - else if (0 != (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED)) - use_chunked = true; - else if (! use_keepalive) - use_chunked = false; else + /* If chunked encoding is supported and allowed, and response size + * is unknown, use chunked even for non-Keep-Alive connections. + * See https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.3 + * Also use chunked if it is enforced by application and supported by + * the client. */ use_chunked = true; } else use_chunked = false; if ( (MHD_SIZE_UNKNOWN == r->total_size) && ! use_chunked) + { + mhd_assert (! MHD_IS_HTTP_VER_1_1_COMPAT (c->http_ver)); use_keepalive = false; /* End of the stream is indicated by closure */ + } } c->rp_props.chunked = use_chunked;