BUG/MEDIUM: lua: In some case, the return of sample-fetches is ignored (2)

This problem is already detected here:

   8dc7316a6fa8cc6f3a60456376c8a13a6902a5be

Another case raises. Now HAProxy sends a final message (typically
with "http-request deny"). Once the the message is sent, the response
channel flags are not modified.

HAProxy executes a Lua sample-fecthes for building logs, and the
result is ignored because the response flag remains set to the value
HTTP_MSG_RPBEFORE. So the Lua function hlua_check_proto() want to
guarantee the valid state of the buffer and ask for aborting the
request.

The function check_proto() is not the good way to ensure request
consistency. The real question is not "Are the message valid ?", but
"Are the validity of message unchanged ?"

This patch memorize the parser state before entering int the Lua
code, and perform a check when it go out of the Lua code. If the parser
state change for down, the request is aborted because the HTTP message
is degraded.

This patch should be backported in version 1.6 and 1.7
diff --git a/include/types/hlua.h b/include/types/hlua.h
index 42cfe3b..214651f 100644
--- a/include/types/hlua.h
+++ b/include/types/hlua.h
@@ -49,6 +49,22 @@
 	HLUA_E_ERR,    /* LUA stack execution failed without error message. */
 };
 
+/* This struct is use for storing HAProxy parsers state
+ * before executing some Lua code. The goal is we can
+ * check and compare the parser state a the end of Lua
+ * execution. If the state is changed by Lua towards
+ * an unexpected state, we can abort the transaction.
+ */
+struct hlua_consistency {
+	enum pr_mode mode;
+	union {
+		struct {
+			int dir;
+			enum ht_state state;
+		} http;
+	} data;
+};
+
 struct hlua {
 	lua_State *T; /* The LUA stack. */
 	int Tref; /* The reference of the stack in coroutine case.
@@ -65,6 +81,7 @@
 	                      We must wake this task to continue the task execution */
 	struct list com; /* The list head of the signals attached to this task. */
 	struct ebpt_node node;
+	struct hlua_consistency cons; /* Store data consistency check. */
 };
 
 struct hlua_com {