can only be called when all data of the message are visible by the current
filter. Otherwise, an error is raised, because an earlier filter holding
data back may already have reached the end of the message, or may expose
- data after it.
+ data after it. Nothing is done if the end of the message was already
+ reached. An error is also raised if the message is incomplete, for instance
+ if its headers or its trailers were not fully received.
:param class_httpmessage http_msg: The manipulated HTTP message.
if (!hlua_http_msg_fully_visible(L, msg, htx))
WILL_LJMP(luaL_error(L, "The 'set_eom' function cannot be called when not all data are visible."));
- htx_set_eom(htx);
+ /* Nothing to do if the end of the message was already reached. The
+ * block carrying the EOM flag may have already been forwarded, so the
+ * message state must be checked too. Note it also covers tunnels.
+ */
+ if (htx_msg_ended(htx) || msg->msg_state >= HTTP_MSG_ENDING)
+ return 0;
+
+ /* The EOM flag can only be carried by an EOH, a DATA, an EOT or a
+ * NOOP block. A NOOP block is added if the message is empty.
+ */
+ if (!htx_is_empty(htx)) {
+ enum htx_blk_type type = htx_get_tail_type(htx);
+
+ if (type != HTX_BLK_EOH && type != HTX_BLK_DATA &&
+ type != HTX_BLK_EOT && type != HTX_BLK_NOOP)
+ WILL_LJMP(luaL_error(L, "The 'set_eom' function cannot be called on an incomplete message."));
+ }
+
+ if (!htx_set_eom(htx))
+ WILL_LJMP(luaL_error(L, "Unable to set the end of message."));
return 0;
}