diff --git a/src/http_fetch.c b/src/http_fetch.c index 2d3a381c4..e16d7bf4c 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -1435,6 +1435,16 @@ static int smp_fetch_hdr(const struct arg *args, struct sample *smp, const char return 0; } +/* Same than smp_fetch_hdr() but only relies on the sample direction to choose + * the right channel. So instead of duplicating the code, we just change the + * keyword and then fallback on smp_fetch_hdr(). + */ +static int smp_fetch_chn_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private) +{ + kw = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ ? "req.hdr" : "res.hdr"); + return smp_fetch_hdr(args, smp, kw, private); +} + /* 6. Check on HTTP header count. The number of occurrences is returned. * Accepts exactly 1 argument of type string. */ @@ -2289,6 +2299,16 @@ static int smp_fetch_cookie(const struct arg *args, struct sample *smp, const ch return found; } +/* Same than smp_fetch_cookie() but only relies on the sample direction to + * choose the right channel. So instead of duplicating the code, we just change + * the keyword and then fallback on smp_fetch_cookie(). + */ +static int smp_fetch_chn_cookie(const struct arg *args, struct sample *smp, const char *kw, void *private) +{ + kw = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ ? "req.cook" : "res.cook"); + return smp_fetch_cookie(args, smp, kw, private); +} + /* Iterate over all cookies present in a request to count how many occurrences * match the name in args and args->data.str.len. If is non-null, then * multiple cookies may be parsed on the same line. The returned sample is of @@ -2825,7 +2845,7 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { * for ACL compatibility only. */ { "cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV }, - { "cookie", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV }, + { "cookie", smp_fetch_chn_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV }, { "cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, { "cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, @@ -2833,7 +2853,7 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { * only here to match the ACL's name, are request-only and are used for * ACL compatibility only. */ - { "hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV }, + { "hdr", smp_fetch_chn_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV }, { "hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, { "hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRQHV }, { "hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRQHV },