mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
MINOR: proxy: Register keywords to parse errorfile and errorloc directives
errorfile and errorloc directives are now pased in dedicated functions in http_htx.c.
This commit is contained in:
parent
5885775de1
commit
07f41f79cb
@ -3805,56 +3805,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
goto out;
|
||||
}
|
||||
else if (!strcmp(args[0], "errorloc") ||
|
||||
!strcmp(args[0], "errorloc302") ||
|
||||
!strcmp(args[0], "errorloc303")) { /* error location */
|
||||
struct buffer *msg;
|
||||
int errloc, status;
|
||||
|
||||
if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
|
||||
err_code |= ERR_WARN;
|
||||
|
||||
if (*(args[1]) == 0 || *(args[2]) == 0) {
|
||||
ha_alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum, args[0]);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
status = atol(args[1]);
|
||||
errloc = (!strcmp(args[0], "errorloc303") ? 303 : 302);
|
||||
msg = http_parse_errorloc(errloc, status, args[2], &errmsg);
|
||||
if (!msg) {
|
||||
ha_alert("parsing [%s:%d] : %s: %s\n", file, linenum, args[0], errmsg);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
goto out;
|
||||
}
|
||||
rc = http_get_status_idx(status);
|
||||
curproxy->errmsg[rc] = msg;
|
||||
}
|
||||
else if (!strcmp(args[0], "errorfile")) { /* error message from a file */
|
||||
struct buffer *msg;
|
||||
int status;
|
||||
|
||||
if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
|
||||
err_code |= ERR_WARN;
|
||||
|
||||
if (*(args[1]) == 0 || *(args[2]) == 0) {
|
||||
ha_alert("parsing [%s:%d] : %s: expects <status_code> and <file> as arguments.\n",
|
||||
file, linenum, args[0]);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
status = atol(args[1]);
|
||||
msg = http_parse_errorfile(status, args[2], &errmsg);
|
||||
if (!msg) {
|
||||
ha_alert("parsing [%s:%d] : %s: %s\n", file, linenum, args[0], errmsg);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
goto out;
|
||||
}
|
||||
rc = http_get_status_idx(status);
|
||||
curproxy->errmsg[rc] = msg;
|
||||
}
|
||||
else {
|
||||
struct cfg_kw_list *kwl;
|
||||
int index;
|
||||
|
@ -1050,6 +1050,87 @@ struct buffer *http_parse_errorloc(int errloc, int status, const char *url, char
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Parses the "errorloc[302|303]" proxy keyword */
|
||||
static int proxy_parse_errorloc(char **args, int section, struct proxy *curpx,
|
||||
struct proxy *defpx, const char *file, int line,
|
||||
char **errmsg)
|
||||
{
|
||||
struct buffer *msg;
|
||||
int errloc, status, rc, ret = 0;
|
||||
|
||||
if (warnifnotcap(curpx, PR_CAP_FE | PR_CAP_BE, file, line, args[0], NULL)) {
|
||||
ret = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (*(args[1]) == 0 || *(args[2]) == 0) {
|
||||
memprintf(errmsg, "%s : expects <status_code> and <url> as arguments.\n", args[0]);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
status = atol(args[1]);
|
||||
errloc = (!strcmp(args[0], "errorloc303") ? 303 : 302);
|
||||
msg = http_parse_errorloc(errloc, status, args[2], errmsg);
|
||||
if (!msg) {
|
||||
memprintf(errmsg, "%s : %s", args[0], *errmsg);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = http_get_status_idx(status);
|
||||
curpx->errmsg[rc] = msg;
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Parses the "errorfile" proxy keyword */
|
||||
static int proxy_parse_errorfile(char **args, int section, struct proxy *curpx,
|
||||
struct proxy *defpx, const char *file, int line,
|
||||
char **errmsg)
|
||||
{
|
||||
struct buffer *msg;
|
||||
int status, rc, ret = 0;
|
||||
|
||||
if (warnifnotcap(curpx, PR_CAP_FE | PR_CAP_BE, file, line, args[0], NULL)) {
|
||||
ret = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (*(args[1]) == 0 || *(args[2]) == 0) {
|
||||
memprintf(errmsg, "%s : expects <status_code> and <file> as arguments.\n", args[0]);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
status = atol(args[1]);
|
||||
msg = http_parse_errorfile(status, args[2], errmsg);
|
||||
if (!msg) {
|
||||
memprintf(errmsg, "%s : %s", args[0], *errmsg);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = http_get_status_idx(status);
|
||||
curpx->errmsg[rc] = msg;
|
||||
|
||||
out:
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
static struct cfg_kw_list cfg_kws = {ILH, {
|
||||
{ CFG_LISTEN, "errorloc", proxy_parse_errorloc },
|
||||
{ CFG_LISTEN, "errorloc302", proxy_parse_errorloc },
|
||||
{ CFG_LISTEN, "errorloc303", proxy_parse_errorloc },
|
||||
{ CFG_LISTEN, "errorfile", proxy_parse_errorfile },
|
||||
{ 0, NULL, NULL },
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
|
||||
|
||||
/************************************************************************/
|
||||
/* HTX sample fetches */
|
||||
/************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user