]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: config: report misplaced http-request rules
authorWilly Tarreau <w@1wt.eu>
Tue, 22 Apr 2014 23:32:02 +0000 (01:32 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 22 Apr 2014 23:32:02 +0000 (01:32 +0200)
Recently, the http-request ruleset started to be used a lot and some
bug reports were caused by misplaced http-request rules because there
was no warning if they're after a redirect or use_backend rule. Let's
fix this now. http-request rules are just after the block rules.

src/cfgparse.c

index 53b136a36a63f6e1f9c1ef64ca954d43af4f0db6..7249062ee70e108ea2cd0da2bb40353e68142856 100644 (file)
@@ -320,6 +320,19 @@ int warnif_rule_after_block(struct proxy *proxy, const char *file, int line, con
        return 0;
 }
 
+/* Report a warning if a rule is placed after an 'http_request' rule.
+ * Return 1 if the warning has been emitted, otherwise 0.
+ */
+int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
+{
+       if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
+               Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
+                       file, line, arg);
+               return 1;
+       }
+       return 0;
+}
+
 /* Report a warning if a rule is placed after a reqrewrite rule.
  * Return 1 if the warning has been emitted, otherwise 0.
  */
@@ -374,6 +387,16 @@ int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int lin
 
 /* report a warning if a block rule is dangerously placed */
 int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, const char *arg)
+{
+       return  warnif_rule_after_http_req(proxy, file, line, arg) ||
+               warnif_rule_after_reqxxx(proxy, file, line, arg) ||
+               warnif_rule_after_reqadd(proxy, file, line, arg) ||
+               warnif_rule_after_redirect(proxy, file, line, arg) ||
+               warnif_rule_after_use_backend(proxy, file, line, arg);
+}
+
+/* report a warning if an http-request rule is dangerously placed */
+int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
 {
        return  warnif_rule_after_reqxxx(proxy, file, line, arg) ||
                warnif_rule_after_reqadd(proxy, file, line, arg) ||
@@ -2748,6 +2771,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
+               err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
                err_code |= warnif_cond_conflicts(rule->cond,
                                                  (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
                                                  file, linenum);