MEDIUM: http: remove the now useless http_txn from {req/res} rules
The registerable http_req_rules / http_res_rules used to require a
struct http_txn at the end. It's redundant with struct stream and
propagates very deep into some parts (ie: it was the reason for lua
requiring l7). Let's remove it now.
diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h
index 97b3096..361072e 100644
--- a/include/proto/proto_http.h
+++ b/include/proto/proto_http.h
@@ -99,8 +99,7 @@
int http_header_match2(const char *hdr, const char *end, const char *name, int len);
int http_remove_header2(struct http_msg *msg, struct hdr_idx *idx, struct hdr_ctx *ctx);
int http_header_add_tail2(struct http_msg *msg, struct hdr_idx *hdr_idx, const char *text, int len);
-int http_replace_req_line(int action, const char *replace, int len,
- struct proxy *px, struct stream *s, struct http_txn *txn);
+int http_replace_req_line(int action, const char *replace, int len, struct proxy *px, struct stream *s);
int http_transform_header_str(struct stream* s, struct http_msg *msg, const char* name,
unsigned int name_len, const char *str, struct my_regex *re,
int action);
diff --git a/include/types/proto_http.h b/include/types/proto_http.h
index d1fdf75..611cafe 100644
--- a/include/types/proto_http.h
+++ b/include/types/proto_http.h
@@ -416,7 +416,7 @@
struct list list;
struct acl_cond *cond; /* acl condition to meet */
unsigned int action; /* HTTP_REQ_* */
- int (*action_ptr)(struct http_req_rule *rule, struct proxy *px, struct stream *s, struct http_txn *http_txn); /* ptr to custom action */
+ int (*action_ptr)(struct http_req_rule *rule, struct proxy *px, struct stream *s); /* ptr to custom action */
union {
struct {
char *realm;
@@ -452,7 +452,7 @@
struct list list;
struct acl_cond *cond; /* acl condition to meet */
unsigned int action; /* HTTP_RES_* */
- int (*action_ptr)(struct http_res_rule *rule, struct proxy *px, struct stream *s, struct http_txn *http_txn); /* ptr to custom action */
+ int (*action_ptr)(struct http_res_rule *rule, struct proxy *px, struct stream *s); /* ptr to custom action */
union {
struct {
char *name; /* header name */
diff --git a/src/hlua.c b/src/hlua.c
index b278e11..f471a6d 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -3205,9 +3205,8 @@
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
size_t name_len;
const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
- struct http_txn *txn = htxn->s->txn;
- lua_pushboolean(L, http_replace_req_line(0, name, name_len, htxn->p, htxn->s, txn) != -1);
+ lua_pushboolean(L, http_replace_req_line(0, name, name_len, htxn->p, htxn->s) != -1);
return 1;
}
@@ -3217,9 +3216,7 @@
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
size_t name_len;
const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
- struct http_txn *txn = htxn->s->txn;
-
- lua_pushboolean(L, http_replace_req_line(1, name, name_len, htxn->p, htxn->s, txn) != -1);
+ lua_pushboolean(L, http_replace_req_line(1, name, name_len, htxn->p, htxn->s) != -1);
return 1;
}
@@ -3229,7 +3226,6 @@
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
size_t name_len;
const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
- struct http_txn *txn = htxn->s->txn;
/* Check length. */
if (name_len > trash.size - 1) {
@@ -3243,7 +3239,7 @@
memcpy(trash.str + trash.len, name, name_len);
trash.len += name_len;
- lua_pushboolean(L, http_replace_req_line(2, trash.str, trash.len, htxn->p, htxn->s, txn) != -1);
+ lua_pushboolean(L, http_replace_req_line(2, trash.str, trash.len, htxn->p, htxn->s) != -1);
return 1;
}
@@ -3253,9 +3249,8 @@
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
size_t name_len;
const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
- struct http_txn *txn = htxn->s->txn;
- lua_pushboolean(L, http_replace_req_line(3, name, name_len, htxn->p, htxn->s, txn) != -1);
+ lua_pushboolean(L, http_replace_req_line(3, name, name_len, htxn->p, htxn->s) != -1);
return 1;
}
@@ -4322,10 +4317,10 @@
* the LUA code.
*/
int hlua_http_req_act_wrapper(struct http_req_rule *rule, struct proxy *px,
- struct stream *s, struct http_txn *http_txn)
+ struct stream *s)
{
return hlua_request_act_wrapper((struct hlua_rule *)rule->arg.data, px,
- s, http_txn, AN_REQ_HTTP_PROCESS_FE);
+ s, s->txn, AN_REQ_HTTP_PROCESS_FE);
}
/* Lua execution wrapper for http-response.
@@ -4333,10 +4328,10 @@
* the LUA code.
*/
int hlua_http_res_act_wrapper(struct http_res_rule *rule, struct proxy *px,
- struct stream *s, struct http_txn *http_txn)
+ struct stream *s)
{
return hlua_request_act_wrapper((struct hlua_rule *)rule->arg.data, px,
- s, http_txn, AN_RES_HTTP_PROCESS_BE);
+ s, s->txn, AN_RES_HTTP_PROCESS_BE);
}
/* tcp-request <*> configuration wrapper. */
diff --git a/src/proto_http.c b/src/proto_http.c
index 61b29a1..7825d5c 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -3326,9 +3326,10 @@
* on txn->flags if it encounters a tarpit rule.
*/
enum rule_result
-http_req_get_intercept_rule(struct proxy *px, struct list *rules, struct stream *s, struct http_txn *txn)
+http_req_get_intercept_rule(struct proxy *px, struct list *rules, struct stream *s)
{
struct session *sess = strm_sess(s);
+ struct http_txn *txn = s->txn;
struct connection *cli_conn;
struct http_req_rule *rule;
struct hdr_ctx ctx;
@@ -3543,14 +3544,14 @@
}
case HTTP_REQ_ACT_CUSTOM_CONT:
- if (!rule->action_ptr(rule, px, s, txn)) {
+ if (!rule->action_ptr(rule, px, s)) {
s->current_rule = &rule->list;
return HTTP_RULE_RES_YIELD;
}
break;
case HTTP_REQ_ACT_CUSTOM_STOP:
- rule->action_ptr(rule, px, s, txn);
+ rule->action_ptr(rule, px, s);
return HTTP_RULE_RES_DONE;
case HTTP_REQ_ACT_TRK_SC0 ... HTTP_REQ_ACT_TRK_SCMAX:
@@ -3602,9 +3603,10 @@
* the same context.
*/
static enum rule_result
-http_res_get_intercept_rule(struct proxy *px, struct list *rules, struct stream *s, struct http_txn *txn)
+http_res_get_intercept_rule(struct proxy *px, struct list *rules, struct stream *s)
{
struct session *sess = strm_sess(s);
+ struct http_txn *txn = s->txn;
struct connection *cli_conn;
struct http_res_rule *rule;
struct hdr_ctx ctx;
@@ -3790,14 +3792,14 @@
}
case HTTP_RES_ACT_CUSTOM_CONT:
- if (!rule->action_ptr(rule, px, s, txn)) {
+ if (!rule->action_ptr(rule, px, s)) {
s->current_rule = &rule->list;
return HTTP_RULE_RES_YIELD;
}
break;
case HTTP_RES_ACT_CUSTOM_STOP:
- rule->action_ptr(rule, px, s, txn);
+ rule->action_ptr(rule, px, s);
return HTTP_RULE_RES_STOP;
}
}
@@ -4098,7 +4100,7 @@
/* evaluate http-request rules */
if (!LIST_ISEMPTY(&px->http_req_rules)) {
- verdict = http_req_get_intercept_rule(px, &px->http_req_rules, s, txn);
+ verdict = http_req_get_intercept_rule(px, &px->http_req_rules, s);
switch (verdict) {
case HTTP_RULE_RES_YIELD: /* some data miss, call the function later. */
@@ -4144,7 +4146,7 @@
/* parse the whole stats request and extract the relevant information */
http_handle_stats(s, req);
- verdict = http_req_get_intercept_rule(px, &px->uri_auth->http_req_rules, s, txn);
+ verdict = http_req_get_intercept_rule(px, &px->uri_auth->http_req_rules, s);
/* not all actions implemented: deny, allow, auth */
if (verdict == HTTP_RULE_RES_DENY) /* stats http-request deny */
@@ -6344,7 +6346,7 @@
/* evaluate http-response rules */
if (ret == HTTP_RULE_RES_CONT)
- ret = http_res_get_intercept_rule(cur_proxy, &cur_proxy->http_res_rules, s, txn);
+ ret = http_res_get_intercept_rule(cur_proxy, &cur_proxy->http_res_rules, s);
/* we need to be called again. */
if (ret == HTTP_RULE_RES_YIELD) {
@@ -11696,8 +11698,9 @@
* string by the caller, event if the replacement query string is empty.
*/
int http_replace_req_line(int action, const char *replace, int len,
- struct proxy *px, struct stream *s, struct http_txn *txn)
+ struct proxy *px, struct stream *s)
{
+ struct http_txn *txn = s->txn;
char *cur_ptr, *cur_end;
int offset = 0;
int delta;
@@ -11777,7 +11780,7 @@
* http_action_set_req_line_exec(). It always returns 1. If an error occurs
* the action is canceled, but the rule processing continue.
*/
-int http_action_set_req_line(struct http_req_rule *rule, struct proxy *px, struct stream *s, struct http_txn *txn)
+int http_action_set_req_line(struct http_req_rule *rule, struct proxy *px, struct stream *s)
{
chunk_reset(&trash);
@@ -11786,7 +11789,7 @@
trash.str[trash.len++] = '?';
trash.len += build_logline(s, trash.str + trash.len, trash.size - trash.len, (struct list *)&rule->arg.act.p[0]);
- http_replace_req_line(*(int *)&rule->arg.act.p[2], trash.str, trash.len, px, s, txn);
+ http_replace_req_line(*(int *)&rule->arg.act.p[2], trash.str, trash.len, px, s);
return 1;
}