mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-24 23:31:40 +02:00
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.
This commit is contained in:
parent
f3bf3050a1
commit
987e3fb868
@ -99,8 +99,7 @@ char *find_hdr_value_end(char *s, const char *e);
|
|||||||
int http_header_match2(const char *hdr, const char *end, const char *name, int len);
|
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_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_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,
|
int http_replace_req_line(int action, const char *replace, int len, struct proxy *px, struct stream *s);
|
||||||
struct proxy *px, struct stream *s, struct http_txn *txn);
|
|
||||||
int http_transform_header_str(struct stream* s, struct http_msg *msg, const char* name,
|
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,
|
unsigned int name_len, const char *str, struct my_regex *re,
|
||||||
int action);
|
int action);
|
||||||
|
@ -416,7 +416,7 @@ struct http_req_rule {
|
|||||||
struct list list;
|
struct list list;
|
||||||
struct acl_cond *cond; /* acl condition to meet */
|
struct acl_cond *cond; /* acl condition to meet */
|
||||||
unsigned int action; /* HTTP_REQ_* */
|
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 {
|
union {
|
||||||
struct {
|
struct {
|
||||||
char *realm;
|
char *realm;
|
||||||
@ -452,7 +452,7 @@ struct http_res_rule {
|
|||||||
struct list list;
|
struct list list;
|
||||||
struct acl_cond *cond; /* acl condition to meet */
|
struct acl_cond *cond; /* acl condition to meet */
|
||||||
unsigned int action; /* HTTP_RES_* */
|
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 {
|
union {
|
||||||
struct {
|
struct {
|
||||||
char *name; /* header name */
|
char *name; /* header name */
|
||||||
|
21
src/hlua.c
21
src/hlua.c
@ -3205,9 +3205,8 @@ static int hlua_http_req_set_meth(lua_State *L)
|
|||||||
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
|
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
|
||||||
size_t name_len;
|
size_t name_len;
|
||||||
const char *name = MAY_LJMP(luaL_checklstring(L, 2, &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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3217,9 +3216,7 @@ static int hlua_http_req_set_path(lua_State *L)
|
|||||||
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
|
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
|
||||||
size_t name_len;
|
size_t name_len;
|
||||||
const char *name = MAY_LJMP(luaL_checklstring(L, 2, &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) != -1);
|
||||||
|
|
||||||
lua_pushboolean(L, http_replace_req_line(1, name, name_len, htxn->p, htxn->s, txn) != -1);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3229,7 +3226,6 @@ static int hlua_http_req_set_query(lua_State *L)
|
|||||||
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
|
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
|
||||||
size_t name_len;
|
size_t name_len;
|
||||||
const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
|
const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
|
||||||
struct http_txn *txn = htxn->s->txn;
|
|
||||||
|
|
||||||
/* Check length. */
|
/* Check length. */
|
||||||
if (name_len > trash.size - 1) {
|
if (name_len > trash.size - 1) {
|
||||||
@ -3243,7 +3239,7 @@ static int hlua_http_req_set_query(lua_State *L)
|
|||||||
memcpy(trash.str + trash.len, name, name_len);
|
memcpy(trash.str + trash.len, name, name_len);
|
||||||
trash.len += 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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3253,9 +3249,8 @@ static int hlua_http_req_set_uri(lua_State *L)
|
|||||||
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
|
struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
|
||||||
size_t name_len;
|
size_t name_len;
|
||||||
const char *name = MAY_LJMP(luaL_checklstring(L, 2, &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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4322,10 +4317,10 @@ int hlua_tcp_res_act_wrapper(struct tcp_rule *tcp_rule, struct proxy *px,
|
|||||||
* the LUA code.
|
* the LUA code.
|
||||||
*/
|
*/
|
||||||
int hlua_http_req_act_wrapper(struct http_req_rule *rule, struct proxy *px,
|
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,
|
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.
|
/* Lua execution wrapper for http-response.
|
||||||
@ -4333,10 +4328,10 @@ int hlua_http_req_act_wrapper(struct http_req_rule *rule, struct proxy *px,
|
|||||||
* the LUA code.
|
* the LUA code.
|
||||||
*/
|
*/
|
||||||
int hlua_http_res_act_wrapper(struct http_res_rule *rule, struct proxy *px,
|
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,
|
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. */
|
/* tcp-request <*> configuration wrapper. */
|
||||||
|
@ -3326,9 +3326,10 @@ static int http_transform_header(struct stream* s, struct http_msg *msg,
|
|||||||
* on txn->flags if it encounters a tarpit rule.
|
* on txn->flags if it encounters a tarpit rule.
|
||||||
*/
|
*/
|
||||||
enum rule_result
|
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 session *sess = strm_sess(s);
|
||||||
|
struct http_txn *txn = s->txn;
|
||||||
struct connection *cli_conn;
|
struct connection *cli_conn;
|
||||||
struct http_req_rule *rule;
|
struct http_req_rule *rule;
|
||||||
struct hdr_ctx ctx;
|
struct hdr_ctx ctx;
|
||||||
@ -3543,14 +3544,14 @@ resume_execution:
|
|||||||
}
|
}
|
||||||
|
|
||||||
case HTTP_REQ_ACT_CUSTOM_CONT:
|
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;
|
s->current_rule = &rule->list;
|
||||||
return HTTP_RULE_RES_YIELD;
|
return HTTP_RULE_RES_YIELD;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HTTP_REQ_ACT_CUSTOM_STOP:
|
case HTTP_REQ_ACT_CUSTOM_STOP:
|
||||||
rule->action_ptr(rule, px, s, txn);
|
rule->action_ptr(rule, px, s);
|
||||||
return HTTP_RULE_RES_DONE;
|
return HTTP_RULE_RES_DONE;
|
||||||
|
|
||||||
case HTTP_REQ_ACT_TRK_SC0 ... HTTP_REQ_ACT_TRK_SCMAX:
|
case HTTP_REQ_ACT_TRK_SC0 ... HTTP_REQ_ACT_TRK_SCMAX:
|
||||||
@ -3602,9 +3603,10 @@ resume_execution:
|
|||||||
* the same context.
|
* the same context.
|
||||||
*/
|
*/
|
||||||
static enum rule_result
|
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 session *sess = strm_sess(s);
|
||||||
|
struct http_txn *txn = s->txn;
|
||||||
struct connection *cli_conn;
|
struct connection *cli_conn;
|
||||||
struct http_res_rule *rule;
|
struct http_res_rule *rule;
|
||||||
struct hdr_ctx ctx;
|
struct hdr_ctx ctx;
|
||||||
@ -3790,14 +3792,14 @@ resume_execution:
|
|||||||
}
|
}
|
||||||
|
|
||||||
case HTTP_RES_ACT_CUSTOM_CONT:
|
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;
|
s->current_rule = &rule->list;
|
||||||
return HTTP_RULE_RES_YIELD;
|
return HTTP_RULE_RES_YIELD;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HTTP_RES_ACT_CUSTOM_STOP:
|
case HTTP_RES_ACT_CUSTOM_STOP:
|
||||||
rule->action_ptr(rule, px, s, txn);
|
rule->action_ptr(rule, px, s);
|
||||||
return HTTP_RULE_RES_STOP;
|
return HTTP_RULE_RES_STOP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4098,7 +4100,7 @@ int http_process_req_common(struct stream *s, struct channel *req, int an_bit, s
|
|||||||
|
|
||||||
/* evaluate http-request rules */
|
/* evaluate http-request rules */
|
||||||
if (!LIST_ISEMPTY(&px->http_req_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) {
|
switch (verdict) {
|
||||||
case HTTP_RULE_RES_YIELD: /* some data miss, call the function later. */
|
case HTTP_RULE_RES_YIELD: /* some data miss, call the function later. */
|
||||||
@ -4144,7 +4146,7 @@ int http_process_req_common(struct stream *s, struct channel *req, int an_bit, s
|
|||||||
|
|
||||||
/* parse the whole stats request and extract the relevant information */
|
/* parse the whole stats request and extract the relevant information */
|
||||||
http_handle_stats(s, req);
|
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 */
|
/* not all actions implemented: deny, allow, auth */
|
||||||
|
|
||||||
if (verdict == HTTP_RULE_RES_DENY) /* stats http-request deny */
|
if (verdict == HTTP_RULE_RES_DENY) /* stats http-request deny */
|
||||||
@ -6344,7 +6346,7 @@ int http_process_res_common(struct stream *s, struct channel *rep, int an_bit, s
|
|||||||
|
|
||||||
/* evaluate http-response rules */
|
/* evaluate http-response rules */
|
||||||
if (ret == HTTP_RULE_RES_CONT)
|
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. */
|
/* we need to be called again. */
|
||||||
if (ret == HTTP_RULE_RES_YIELD) {
|
if (ret == HTTP_RULE_RES_YIELD) {
|
||||||
@ -11696,8 +11698,9 @@ expect_comma:
|
|||||||
* string by the caller, event if the replacement query string is empty.
|
* string by the caller, event if the replacement query string is empty.
|
||||||
*/
|
*/
|
||||||
int http_replace_req_line(int action, const char *replace, int len,
|
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;
|
char *cur_ptr, *cur_end;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int delta;
|
int delta;
|
||||||
@ -11777,7 +11780,7 @@ int http_replace_req_line(int action, const char *replace, int len,
|
|||||||
* http_action_set_req_line_exec(). It always returns 1. If an error occurs
|
* http_action_set_req_line_exec(). It always returns 1. If an error occurs
|
||||||
* the action is canceled, but the rule processing continue.
|
* 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);
|
chunk_reset(&trash);
|
||||||
|
|
||||||
@ -11786,7 +11789,7 @@ int http_action_set_req_line(struct http_req_rule *rule, struct proxy *px, struc
|
|||||||
trash.str[trash.len++] = '?';
|
trash.str[trash.len++] = '?';
|
||||||
trash.len += build_logline(s, trash.str + trash.len, trash.size - trash.len, (struct list *)&rule->arg.act.p[0]);
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user