|
commit ff96b8bd3f85155f65b2b9c9f046fe3e40f630a4
|
|
Author: Christopher Faulet <cfaulet@haproxy.com>
|
|
Date: Fri Jul 26 15:09:53 2019 +0200
|
|
|
|
MINOR: hlua: Add a flag on the lua txn to know in which context it can be used
|
|
|
|
When a lua action or a lua sample fetch is called, a lua transaction is
|
|
created. It is an entry in the stack containing the class TXN. Thanks to it, we
|
|
can know the direction (request or response) of the call. But, for some
|
|
functions, it is also necessary to know if the buffer is "HTTP ready" for the
|
|
given direction. "HTTP ready" means there is a valid HTTP message in the
|
|
channel's buffer. So, when a lua action or a lua sample fetch is called, the
|
|
flag HLUA_TXN_HTTP_RDY is set if it is appropriate.
|
|
|
|
(cherry picked from commit bfab2dddad3ded87617d1e2db54761943d1eb32d)
|
|
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
|
|
|
|
diff --git a/include/types/hlua.h b/include/types/hlua.h
|
|
index 70c76852..2f4e38be 100644
|
|
--- a/include/types/hlua.h
|
|
+++ b/include/types/hlua.h
|
|
@@ -43,7 +43,8 @@ struct stream;
|
|
#define HLUA_F_AS_STRING 0x01
|
|
#define HLUA_F_MAY_USE_HTTP 0x02
|
|
|
|
-#define HLUA_TXN_NOTERM 0x00000001
|
|
+#define HLUA_TXN_NOTERM 0x00000001
|
|
+#define HLUA_TXN_HTTP_RDY 0x00000002 /* Set if the txn is HTTP ready for the defined direction */
|
|
|
|
#define HLUA_CONCAT_BLOCSZ 2048
|
|
|
|
diff --git a/src/hlua.c b/src/hlua.c
|
|
index 36454cdc..d37e3c61 100644
|
|
--- a/src/hlua.c
|
|
+++ b/src/hlua.c
|
|
@@ -6494,6 +6494,7 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
|
|
struct stream *stream = smp->strm;
|
|
const char *error;
|
|
const struct buffer msg = { };
|
|
+ unsigned int hflags = HLUA_TXN_NOTERM;
|
|
|
|
if (!stream)
|
|
return 0;
|
|
@@ -6517,6 +6518,13 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
|
|
|
|
consistency_set(stream, smp->opt, &stream->hlua->cons);
|
|
|
|
+ if (stream->be->mode == PR_MODE_HTTP) {
|
|
+ if ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ)
|
|
+ hflags |= ((stream->txn->req.msg_state < HTTP_MSG_BODY) ? 0 : HLUA_TXN_HTTP_RDY);
|
|
+ else
|
|
+ hflags |= ((stream->txn->rsp.msg_state < HTTP_MSG_BODY) ? 0 : HLUA_TXN_HTTP_RDY);
|
|
+ }
|
|
+
|
|
/* If it is the first run, initialize the data for the call. */
|
|
if (!HLUA_IS_RUNNING(stream->hlua)) {
|
|
|
|
@@ -6541,8 +6549,7 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
|
|
lua_rawgeti(stream->hlua->T, LUA_REGISTRYINDEX, fcn->function_ref);
|
|
|
|
/* push arguments in the stack. */
|
|
- if (!hlua_txn_new(stream->hlua->T, stream, smp->px, smp->opt & SMP_OPT_DIR,
|
|
- HLUA_TXN_NOTERM)) {
|
|
+ if (!hlua_txn_new(stream->hlua->T, stream, smp->px, smp->opt & SMP_OPT_DIR, hflags)) {
|
|
SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
|
|
RESET_SAFE_LJMP(stream->hlua->T);
|
|
return 0;
|
|
@@ -6759,16 +6766,16 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
|
|
struct session *sess, struct stream *s, int flags)
|
|
{
|
|
char **arg;
|
|
- unsigned int analyzer;
|
|
+ unsigned int hflags = 0;
|
|
int dir;
|
|
const char *error;
|
|
const struct buffer msg = { };
|
|
|
|
switch (rule->from) {
|
|
- case ACT_F_TCP_REQ_CNT: analyzer = AN_REQ_INSPECT_FE ; dir = SMP_OPT_DIR_REQ; break;
|
|
- case ACT_F_TCP_RES_CNT: analyzer = AN_RES_INSPECT ; dir = SMP_OPT_DIR_RES; break;
|
|
- case ACT_F_HTTP_REQ: analyzer = AN_REQ_HTTP_PROCESS_FE; dir = SMP_OPT_DIR_REQ; break;
|
|
- case ACT_F_HTTP_RES: analyzer = AN_RES_HTTP_PROCESS_BE; dir = SMP_OPT_DIR_RES; break;
|
|
+ case ACT_F_TCP_REQ_CNT: ; dir = SMP_OPT_DIR_REQ; break;
|
|
+ case ACT_F_TCP_RES_CNT: ; dir = SMP_OPT_DIR_RES; break;
|
|
+ case ACT_F_HTTP_REQ: hflags = HLUA_TXN_HTTP_RDY ; dir = SMP_OPT_DIR_REQ; break;
|
|
+ case ACT_F_HTTP_RES: hflags = HLUA_TXN_HTTP_RDY ; dir = SMP_OPT_DIR_RES; break;
|
|
default:
|
|
SEND_ERR(px, "Lua: internal error while execute action.\n");
|
|
return ACT_RET_CONT;
|
|
@@ -6821,7 +6828,7 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
|
|
lua_rawgeti(s->hlua->T, LUA_REGISTRYINDEX, rule->arg.hlua_rule->fcn.function_ref);
|
|
|
|
/* Create and and push object stream in the stack. */
|
|
- if (!hlua_txn_new(s->hlua->T, s, px, dir, 0)) {
|
|
+ if (!hlua_txn_new(s->hlua->T, s, px, dir, hflags)) {
|
|
SEND_ERR(px, "Lua function '%s': full stack.\n",
|
|
rule->arg.hlua_rule->fcn.name);
|
|
RESET_SAFE_LJMP(s->hlua->T);
|
|
@@ -6864,9 +6871,9 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
|
|
case HLUA_E_AGAIN:
|
|
/* Set timeout in the required channel. */
|
|
if (s->hlua->wake_time != TICK_ETERNITY) {
|
|
- if (analyzer & (AN_REQ_INSPECT_FE|AN_REQ_HTTP_PROCESS_FE))
|
|
+ if (dir & SMP_OPT_DIR_REQ)
|
|
s->req.analyse_exp = s->hlua->wake_time;
|
|
- else if (analyzer & (AN_RES_INSPECT|AN_RES_HTTP_PROCESS_BE))
|
|
+ else
|
|
s->res.analyse_exp = s->hlua->wake_time;
|
|
}
|
|
/* Some actions can be wake up when a "write" event
|