]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-rules: Support an optional status on deny rules for http reponses
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 13 Jan 2020 15:43:45 +0000 (16:43 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 20 Jan 2020 14:18:46 +0000 (15:18 +0100)
It is now possible to specified the status code to return an http-response deny
rules. For instance :

    http-response deny deny_status 500

doc/configuration.txt
src/http_act.c
src/http_ana.c

index 1d69380c8a7ed09170f3d9829bff61d27822d945..d12a3ae1c0274bffe00195dba81bd026136f9e88 100644 (file)
@@ -5107,10 +5107,13 @@ http-response del-map(<file-name>) <key fmt> [ { if | unless } <condition> ]
   It takes one argument: "file name" It is the equivalent of the "del map"
   command from the stats socket, but can be triggered by an HTTP response.
 
-http-response deny [ { if | unless } <condition> ]
+http-response deny [deny_status <status>] [ { if | unless } <condition> ]
 
   This stops the evaluation of the rules and immediately rejects the response
-  and emits an HTTP 502 error. No further "http-response" rules are evaluated.
+  and emits an HTTP 502 error, or optionally the status code specified as an
+  argument to "deny_status". The list of permitted status codes is limited to
+  those that can be overridden by the "errorfile" directive.
+  No further "http-response" rules are evaluated.
 
 http-response redirect <rule> [ { if | unless } <condition> ]
 
index 9907425fc0484704b820a630c4de106646117955..9123a7f0afc4f13ec0357bc9079096b926b76118 100644 (file)
@@ -835,8 +835,34 @@ static enum act_parse_ret parse_http_req_deny(const char **args, int *orig_arg,
 static enum act_parse_ret parse_http_res_deny(const char **args, int *orig_arg, struct proxy *px,
                                              struct act_rule *rule, char **err)
 {
-       rule->action = ACT_ACTION_DENY;
+       int code, hc, cur_arg;
+
+       cur_arg = *orig_arg;
+       rule->action = ACT_ACTION_DENY;;
+       rule->arg.http.i = HTTP_ERR_502;
        rule->flags |= ACT_FLAG_FINAL;
+
+       if (strcmp(args[cur_arg], "deny_status") == 0) {
+               cur_arg++;
+               if (!*args[cur_arg]) {
+                       memprintf(err, "missing status code.\n");
+                       return ACT_RET_PRS_ERR;
+               }
+
+               code = atol(args[cur_arg]);
+               cur_arg++;
+               for (hc = 0; hc < HTTP_ERR_SIZE; hc++) {
+                       if (http_err_codes[hc] == code) {
+                               rule->arg.http.i = hc;
+                               break;
+                       }
+               }
+               if (hc >= HTTP_ERR_SIZE)
+                       memprintf(err, "status code %d not handled, using default code %d",
+                                 code, http_err_codes[rule->arg.http.i]);
+       }
+
+       *orig_arg = cur_arg;
        return ACT_RET_PRS_OK;
 }
 
index 628116d9bff13c03073fd521b1b4968615a2ec57..574f6eb01e44e7da0791b92e370606c9fd730b49 100644 (file)
@@ -3073,7 +3073,7 @@ resume_execution:
 
                        case ACT_ACTION_DENY:
                                txn->flags |= TX_CLDENY;
-                               txn->status = 502;
+                               txn->status = http_err_codes[rule->arg.http.i];
                                rule_ret = HTTP_RULE_RES_DENY;
                                goto end;