]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: http-rules: add a new "ignore-empty" option to redirects.
authorWilly Tarreau <w@1wt.eu>
Thu, 2 Sep 2021 14:54:33 +0000 (16:54 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 2 Sep 2021 15:06:18 +0000 (17:06 +0200)
commitbc1223be795ab99346287f69e53978ca893475b2
tree9a7d540206106661267545f8c340ba82eed3e4bf
parentb061fb31aba6fce562b0626b451c926d6c1bc8aa
MINOR: http-rules: add a new "ignore-empty" option to redirects.

Sometimes it is convenient to remap large sets of URIs to new ones (e.g.
after a site migration for example). This can be achieved using
"http-request redirect" combined with maps, but one difficulty there is
that non-matching entries will return an empty response. In order to
avoid this, duplicating the operation as an ACL condition ending in
"-m found" is possible but it becomes complex and error-prone while it's
known that an empty URL is not valid in a location header.

This patch addresses this by improving the redirect rules to be able to
simply ignore the rule and skip to the next one if the result of the
evaluation of the "location" expression is empty. However in order not
to break existing setups, it requires a new "ignore-empty" keyword.

There used to be an ACT_FLAG_FINAL on redirect rules that's used during
the parsing to emit a warning if followed by another rule, so here we
only set it if the option is not there. The http_apply_redirect_rule()
function now returns a 3rd value to mention that it did nothing and
that this was not an error, so that callers can just ignore the rule.
The regular "redirect" rules were not modified however since this does
not apply there.

The map_redirect VTC was completed with such a test and updated to 2.5
and an example was added into the documentation.
doc/configuration.txt
include/haproxy/http_ana-t.h
reg-tests/http-rules/map_redirect.map
reg-tests/http-rules/map_redirect.vtc
src/http_act.c
src/http_ana.c
src/http_rules.c