MEDIUM: htx: Add a flag on a HTX message when no more data are expected

The HTX_FL_EOI flag must now be set on a HTX message when no more data are
expected. Most of time, it must be set before adding the EOM block. Thus, if
there is no space for the EOM, there is still an information to know all data
were received and pushed in the HTX message. There is only an exception for the
HTTP replies (deny, return...). For these messages, the flag is set after all
blocks are pushed in the message, including the EOM block, because, on error,
we remove all inserted data.
diff --git a/src/cache.c b/src/cache.c
index 6fc1c14..533b902 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -926,6 +926,7 @@
 	}
 
 	if (appctx->st0 == HTX_CACHE_EOM) {
+		res_htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
 		if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
 			si_rx_room_blk(si);
 			goto out;
diff --git a/src/h1_htx.c b/src/h1_htx.c
index 351980b..a2ee510 100644
--- a/src/h1_htx.c
+++ b/src/h1_htx.c
@@ -616,6 +616,8 @@
 		dsthtx->flags |= HTX_FL_PARSING_ERROR;
 		return 0;
 	}
+
+	dsthtx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
 	if (max < sizeof(struct htx_blk) + 1 || !htx_add_endof(dsthtx, HTX_BLK_EOM))
 		return 0;
 
diff --git a/src/hlua.c b/src/hlua.c
index 254c2a3..556de42 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -4582,6 +4582,7 @@
 	}
 
 	/* Finalize headers. */
+	htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
 	if (!htx_add_endof(htx, HTX_BLK_EOH)) {
 		hlua_pusherror(L, "Lua applet http '%s': Failed create the response.\n",
 			       appctx->appctx->rule->arg.hlua_rule->fcn.name);
diff --git a/src/http_ana.c b/src/http_ana.c
index b77bf2a..7c1a1a1 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -4577,6 +4577,7 @@
 		channel_auto_close(res);
 		channel_shutr_now(res);
 		res->flags |= CF_EOI; /* The response is terminated, add EOI */
+		htxbuf(&res->buf)->flags |= HTX_FL_EOI; /* no more data are expected */
 	}
 	else {
 		/* Send ASAP informational messages. Rely on CF_EOI for final
diff --git a/src/mux_h2.c b/src/mux_h2.c
index 4b790e6..44955ba 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -4452,6 +4452,7 @@
 
 	if ((h2c->dff & H2_F_HEADERS_END_STREAM)) {
 		/* Mark the end of message using EOM */
+		htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
 		if (!htx_add_endof(htx, HTX_BLK_EOM)) {
 			TRACE_STATE("failed to append HTX EOM block into rxbuf", H2_EV_RX_FRAME|H2_EV_RX_HDR|H2_EV_H2S_ERR, h2c->conn);
 			goto fail;
@@ -4587,6 +4588,7 @@
 	 */
 
 	if (h2c->dff & H2_F_DATA_END_STREAM) {
+		htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
 		if (!htx_add_endof(htx, HTX_BLK_EOM)) {
 			TRACE_STATE("h2s rxbuf is full, failed to add EOM", H2_EV_RX_FRAME|H2_EV_RX_DATA|H2_EV_H2S_BLK, h2c->conn, h2s);
 			h2c->flags |= H2_CF_DEM_SFULL;
@@ -5778,6 +5780,8 @@
 		if (htx_is_empty(buf_htx))
 			cs->flags |= CS_FL_EOI;
 	}
+	else if (htx_is_empty(h2s_htx))
+		buf_htx->flags |= (h2s_htx->flags & HTX_FL_EOI);
 
 	buf_htx->extra = (h2s_htx->extra ? (h2s_htx->data + h2s_htx->extra) : 0);
 	htx_to_buf(buf_htx, buf);
diff --git a/src/stats.c b/src/stats.c
index d69c764..562cd82 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -3339,6 +3339,7 @@
 
 	if (appctx->st0 == STAT_HTTP_DONE) {
 		/* Don't add TLR because mux-h1 will take care of it */
+		res_htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
 		if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
 			si_rx_room_blk(si);
 			goto out;
diff --git a/src/tcpcheck.c b/src/tcpcheck.c
index e83b915..fc64a10 100644
--- a/src/tcpcheck.c
+++ b/src/tcpcheck.c
@@ -1335,8 +1335,11 @@
 
 
 		if (!htx_add_endof(htx, HTX_BLK_EOH) ||
-		    (istlen(body) && !htx_add_data_atonce(htx, body)) ||
-		    !htx_add_endof(htx, HTX_BLK_EOM))
+		    (istlen(body) && !htx_add_data_atonce(htx, body)))
+			goto error_htx;
+
+		htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
+		if (!htx_add_endof(htx, HTX_BLK_EOM))
 			goto error_htx;
 
 		htx_to_buf(htx, &check->bo);