MINOR: proxy/checks: Move parsing of httpchk option in checks.c
Parsing of the proxy directive "option httpchk" have been moved in checks.c.
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index 1111b74..4c8444c 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -2330,70 +2330,8 @@
curproxy->options |= PR_O_TCP_SRV_KA;
}
else if (!strcmp(args[1], "httpchk")) {
- if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
- err_code |= ERR_WARN;
-
- /* use HTTP request to check servers' health */
- free(curproxy->check_req);
- free(curproxy->check_hdrs);
- free(curproxy->check_body);
- curproxy->check_req = curproxy->check_hdrs = curproxy->check_body = NULL;
- curproxy->check_len = curproxy->check_hdrs_len = curproxy->check_body_len = 0;
- curproxy->options2 &= ~PR_O2_CHK_ANY;
- curproxy->options2 |= PR_O2_HTTP_CHK;
- if (!*args[2]) { /* no argument */
- curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */
- curproxy->check_len = strlen(DEF_CHECK_REQ);
- } else if (!*args[3]) { /* one argument : URI */
- int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n") + 1;
- curproxy->check_req = malloc(reqlen);
- curproxy->check_len = snprintf(curproxy->check_req, reqlen,
- "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */
- } else if (!*args[4]) { /* two arguments : METHOD URI */
- int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" HTTP/1.0\r\n") + 1;
-
- curproxy->check_req = malloc(reqlen);
- curproxy->check_len = snprintf(curproxy->check_req, reqlen,
- "%s %s HTTP/1.0\r\n", args[2], args[3]);
- } else { /* 3 arguments : METHOD URI HTTP_VER */
- char *vsn = args[4];
- char *hdrs = strstr(vsn, "\r\n");
- char *body = strstr(vsn, "\r\n\r\n");
-
- if (hdrs || body) {
- ha_warning("parsing [%s:%d]: '%s %s' : hiding headers or body at the end of the version string is deprecated."
- " Please, consider to use 'http-check send' directive instead.\n",
- file, linenum, args[0], args[1]);
- err_code |= ERR_WARN;
- }
-
- if (hdrs == body)
- hdrs = NULL;
- if (hdrs) {
- *hdrs = '\0';
- hdrs += 2;
- }
- if (body) {
- *body = '\0';
- body += 4;
- }
-
- curproxy->check_len = strlen(args[2]) + strlen(args[3]) + strlen(vsn) + 4;
- curproxy->check_req = malloc(curproxy->check_len+1);
- snprintf(curproxy->check_req, curproxy->check_len+1, "%s %s %s\r\n", args[2], args[3], vsn);
-
- if (hdrs) {
- curproxy->check_hdrs_len = strlen(hdrs) + 2;
- curproxy->check_hdrs = malloc(curproxy->check_hdrs_len+1);
- snprintf(curproxy->check_hdrs, curproxy->check_hdrs_len+1, "%s\r\n", hdrs);
- }
-
- if (body) {
- curproxy->check_body_len = strlen(body);
- curproxy->check_body = strdup(body);
- }
- }
- if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code))
+ err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
+ if (err_code & ERR_FATAL)
goto out;
}
else if (!strcmp(args[1], "ssl-hello-chk")) {
diff --git a/src/checks.c b/src/checks.c
index a94a29c..ceb53ea 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -6043,6 +6043,88 @@
goto out;
}
+int proxy_parse_httpchk_opt(char **args, int cur_arg, struct proxy *curpx, struct proxy *defpx,
+ const char *file, int line)
+{
+ static const char *http_req = "OPTIONS / HTTP/1.0\r\n";
+ int err_code = 0;
+
+ if (warnifnotcap(curpx, PR_CAP_BE, file, line, args[cur_arg+1], NULL))
+ err_code |= ERR_WARN;
+
+ if (alertif_too_many_args_idx(3, 1, file, line, args, &err_code))
+ goto out;
+
+ /* use HTTP request to check servers' health */
+ free(curpx->check_req);
+ free(curpx->check_hdrs);
+ free(curpx->check_body);
+
+ curpx->check_req = curpx->check_hdrs = curpx->check_body = NULL;
+ curpx->check_len = curpx->check_hdrs_len = curpx->check_body_len = 0;
+ curpx->options2 &= ~PR_O2_CHK_ANY;
+ curpx->options2 |= PR_O2_HTTP_CHK;
+
+ cur_arg += 2;
+ if (!*args[cur_arg]) { /* no argument */
+ curpx->check_req = strdup(http_req); /* default request */
+ curpx->check_len = strlen(http_req);
+ }
+ else if (!*args[cur_arg+1]) { /* one argument : URI */
+ curpx->check_len = strlen(args[cur_arg]) + strlen("OPTIONS HTTP/1.0\r\n");
+ curpx->check_req = malloc(curpx->check_len+1);
+ curpx->check_len = snprintf(curpx->check_req, curpx->check_len+1,
+ "OPTIONS %s HTTP/1.0\r\n", args[cur_arg]);
+ }
+ else if (!*args[cur_arg+2]) { /* two arguments : METHOD URI */
+ curpx->check_len = strlen(args[cur_arg]) + strlen(args[cur_arg+1]) + strlen(" HTTP/1.0\r\n") + 1;
+ curpx->check_req = malloc(curpx->check_len+1);
+ curpx->check_len = snprintf(curpx->check_req, curpx->check_len+1,
+ "%s %s HTTP/1.0\r\n", args[cur_arg], args[cur_arg+1]);
+ }
+ else { /* 3 arguments : METHOD URI HTTP_VER */
+ char *hdrs = strstr(args[cur_arg+2], "\r\n");
+ char *body = strstr(args[cur_arg+2], "\r\n\r\n");
+
+ if (hdrs || body) {
+ ha_warning("parsing [%s:%d]: '%s %s' : hiding headers or body at the end of the version string is deprecated."
+ " Please, consider to use 'http-check send' directive instead.\n",
+ file, line, args[0], args[1]);
+ err_code |= ERR_WARN;
+ }
+
+ if (hdrs == body)
+ hdrs = NULL;
+ if (hdrs) {
+ *hdrs = '\0';
+ hdrs += 2;
+ }
+ if (body) {
+ *body = '\0';
+ body += 4;
+ }
+
+ curpx->check_len = strlen(args[cur_arg]) + strlen(args[cur_arg+1]) + strlen(args[cur_arg+2]) + 4;
+ curpx->check_req = malloc(curpx->check_len+1);
+ snprintf(curpx->check_req, curpx->check_len+1, "%s %s %s\r\n",
+ args[cur_arg], args[cur_arg+1], args[cur_arg+2]);
+ if (hdrs) {
+ curpx->check_hdrs_len = strlen(hdrs) + 2;
+ curpx->check_hdrs = malloc(curpx->check_hdrs_len+1);
+ snprintf(curpx->check_hdrs, curpx->check_hdrs_len+1, "%s\r\n", hdrs);
+ }
+ if (body) {
+ curpx->check_body_len = strlen(body);
+ curpx->check_body = strdup(body);
+ }
+ }
+ out:
+ return err_code;
+
+ error:
+ err_code |= ERR_ALERT | ERR_FATAL;
+ goto out;
+}
/* Parse the "addr" server keyword */
static int srv_parse_addr(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,