From: Christopher Faulet Date: Mon, 31 Aug 2020 14:27:42 +0000 (+0200) Subject: BUG/MINOR: http-rules: Replace path and query-string in "replace-path" action X-Git-Tag: v2.1.9~39 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=7d360ab50f5201c617c7f93d7c973cf284f3a0b4;p=haproxy-2.1.git BUG/MINOR: http-rules: Replace path and query-string in "replace-path" action The documentation stated the "replace-path" action replaces the path, including the query-string if any is present. But in the code, only the path is replaced. The query-string is preserved. So, now, instead of relying on the same action code than "set-uri" action (1), a new action code (4) is used for "replace-path" action. In http_req_replace_stline() function, when the action code is 4, we call http_replace_req_path() setting the last argument (with_qs) to 1. This way, the query-string is not skipped but included to the path to be replaced. This patch relies on the commit b8ce505c6 ("MINOR: http-htx: Add an option to eval query-string when the path is replaced"). Both must be backported as far as 2.0. It should fix the issue #829. (cherry picked from commit 4b9c0d1fc08388bf44c6ebbd88f786032dd010fc) Signed-off-by: Christopher Faulet (cherry picked from commit 984435789b5aee02671005ad9f098847bbb60a61) Signed-off-by: Christopher Faulet --- diff --git a/src/http_act.c b/src/http_act.c index 1105d59..372147e 100644 --- a/src/http_act.c +++ b/src/http_act.c @@ -152,8 +152,8 @@ static enum act_return http_action_replace_uri(struct act_rule *rule, struct pro goto leave; uri = htx_sl_req_uri(http_get_stline(htxbuf(&s->req.buf))); - if (rule->arg.act.p[0] == (void *)1) - uri = iststop(http_get_path(uri), '?'); + if (rule->arg.act.p[0] == (void *)4) + uri = http_get_path(uri); if (!regex_exec_match2(rule->arg.act.p[1], uri.ptr, uri.len, MAX_MATCH, pmatch, 0)) goto leave; @@ -191,7 +191,7 @@ static enum act_parse_ret parse_replace_uri(const char **args, int *orig_arg, st rule->action = ACT_CUSTOM; if (strcmp(args[cur_arg-1], "replace-path") == 0) - rule->arg.act.p[0] = (void *)1; // replace-path + rule->arg.act.p[0] = (void *)4; // replace-path else rule->arg.act.p[0] = (void *)3; // replace-uri diff --git a/src/http_ana.c b/src/http_ana.c index 63f9135..b63e7fe 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -2795,6 +2795,11 @@ int http_req_replace_stline(int action, const char *replace, int len, return -1; break; + case 4: // path + query + if (!http_replace_req_path(htx, ist2(replace, len), 1)) + return -1; + break; + default: return -1; }