mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-28 14:21:00 +01:00
Revert "MEDIUM: checks: capture groups in expect regexes"
This reverts commit 1979943c30ef285ed04f07ecf829514de971d9b2. Captures in comment was only used when a tcp-check expect based on a negative regex matching failed to eventually report what was captured while it was not expected. It is a bit far-fetched to be useable IMHO. on-error and on-success log-format strings are far more usable. For now there is few check sample fetches (in fact only one...). But it could be really powerful to report info in logs.
This commit is contained in:
parent
aec7f76af8
commit
88d939c831
@ -247,7 +247,6 @@ enum tcpcheck_expect_type {
|
||||
|
||||
/* tcp-check expect flags */
|
||||
#define TCPCHK_EXPT_FL_INV 0x0001 /* Matching is inversed */
|
||||
#define TCPCHK_EXPT_FL_CAP 0x0002 /* Regex matching with capture */
|
||||
|
||||
struct tcpcheck_expect {
|
||||
enum tcpcheck_expect_type type; /* Type of pattern used for matching. */
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
varnishtest "tcp-check expect rule with capture groups"
|
||||
#EXCLUDE_TARGETS=freebsd,osx,generic
|
||||
#REQUIRE_VERSION=2.2
|
||||
#REGTEST_TYPE=slow
|
||||
# This script tests expect rules matching a regex with capture groups and
|
||||
# defining a comment with backreferences. Text and binary regex are tested.
|
||||
feature ignore_unknown_macro
|
||||
|
||||
syslog S1 -level notice {
|
||||
recv
|
||||
expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be1 started."
|
||||
recv
|
||||
expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv1 failed.*code=400 reason=Bad Request"
|
||||
} -start
|
||||
|
||||
syslog S2 -level notice {
|
||||
recv
|
||||
expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be2 started."
|
||||
recv
|
||||
expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be2/srv1 failed.*code=400 reason=Bad Request"
|
||||
} -start
|
||||
|
||||
server s1 {
|
||||
rxreq
|
||||
txresp -status 400 -reason "Bad Request"
|
||||
} -start
|
||||
|
||||
server s2 {
|
||||
rxreq
|
||||
txresp -status 400 -reason "Bad Request"
|
||||
} -start
|
||||
|
||||
haproxy h1 -conf {
|
||||
defaults
|
||||
timeout client 5s
|
||||
timeout connect 5s
|
||||
timeout server 5s
|
||||
timeout check 5s
|
||||
|
||||
backend be1
|
||||
log ${S1_addr}:${S1_port} len 2048 local0
|
||||
option tcp-check
|
||||
option log-health-checks
|
||||
tcp-check connect
|
||||
tcp-check send "GET / HTTP/1.1\r\n\r\n"
|
||||
tcp-check expect !rstring "HTTP/1\\.1\s+([45][0-9]{2})\s+([^\r\n]*)" comment " Bad response: code=\\1 reason=\\2"
|
||||
server srv1 ${s1_addr}:${s1_port} check inter 1000ms rise 1 fall 1
|
||||
|
||||
backend be2
|
||||
log ${S2_addr}:${S2_port} len 2048 local0
|
||||
option tcp-check
|
||||
option log-health-checks
|
||||
tcp-check connect
|
||||
tcp-check send-binary "474554202f20485454502f312e31200d0a0d0a" # GET / HTTP/1.1\r\n\r\n
|
||||
tcp-check expect !rbinary "485454502F312E3120(34[0-9]{4}|35[0-9]{4})20(([^0].)*)" comment " Bad response: code=\\1 reason=\\2"
|
||||
server srv1 ${s2_addr}:${s2_port} check inter 1000ms rise 1 fall 1
|
||||
} -start
|
||||
|
||||
syslog S1 -wait
|
||||
syslog S2 -wait
|
||||
50
src/checks.c
50
src/checks.c
@ -1060,18 +1060,6 @@ static void tcpcheck_expect_onerror_message(struct buffer *msg, struct check *ch
|
||||
break;
|
||||
case TCPCHK_EXPECT_REGEX_BINARY:
|
||||
chunk_appendf(msg, " (binary regex) at step %d", tcpcheck_get_step_id(check, rule));
|
||||
|
||||
/* If references to the matched text were made, divide the
|
||||
* offsets by 2 to match offset of the original response buffer.
|
||||
*/
|
||||
if (rule->expect.flags & TCPCHK_EXPT_FL_CAP) {
|
||||
int i;
|
||||
|
||||
for (i = 1; i < MAX_MATCH && pmatch[i].rm_so != -1; i++) {
|
||||
pmatch[i].rm_so /= 2; /* at first matched char. */
|
||||
pmatch[i].rm_eo /= 2; /* at last matched char. */
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TCPCHK_EXPECT_CUSTOM:
|
||||
chunk_appendf(msg, " (custom function) at step %d", tcpcheck_get_step_id(check, rule));
|
||||
@ -1087,12 +1075,6 @@ static void tcpcheck_expect_onerror_message(struct buffer *msg, struct check *ch
|
||||
*/
|
||||
if (rule->comment) {
|
||||
chunk_strcat(msg, " comment: ");
|
||||
if (rule->expect.flags & TCPCHK_EXPT_FL_CAP) {
|
||||
int ret = exp_replace(b_tail(msg), b_room(msg), b_head(&check->bi), rule->comment, pmatch);
|
||||
if (ret != -1) /* ignore comment if too large */
|
||||
msg->data += ret;
|
||||
}
|
||||
else
|
||||
chunk_strcat(msg, rule->comment);
|
||||
}
|
||||
|
||||
@ -2271,20 +2253,12 @@ static enum tcpcheck_eval_ret tcpcheck_eval_expect(struct check *check, struct t
|
||||
match = my_memmem(b_head(&check->bi), b_data(&check->bi), istptr(expect->data), istlen(expect->data)) != NULL;
|
||||
break;
|
||||
case TCPCHK_EXPECT_REGEX:
|
||||
if (expect->flags & TCPCHK_EXPT_FL_CAP)
|
||||
match = regex_exec_match2(expect->regex, b_head(&check->bi), MIN(b_data(&check->bi), b_size(&check->bi)-1),
|
||||
MAX_MATCH, pmatch, 0);
|
||||
else
|
||||
match = regex_exec2(expect->regex, b_head(&check->bi), MIN(b_data(&check->bi), b_size(&check->bi)-1));
|
||||
break;
|
||||
|
||||
case TCPCHK_EXPECT_REGEX_BINARY:
|
||||
chunk_reset(&trash);
|
||||
dump_binary(&trash, b_head(&check->bi), b_data(&check->bi));
|
||||
if (expect->flags & TCPCHK_EXPT_FL_CAP)
|
||||
match = regex_exec_match2(expect->regex, b_head(&trash), MIN(b_data(&trash), b_size(&trash)-1),
|
||||
MAX_MATCH, pmatch, 0);
|
||||
else
|
||||
match = regex_exec2(expect->regex, b_head(&trash), MIN(b_data(&trash), b_size(&trash)-1));
|
||||
break;
|
||||
case TCPCHK_EXPECT_CUSTOM:
|
||||
@ -3935,7 +3909,7 @@ static struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, str
|
||||
enum healthcheck_status err_st = HCHK_STATUS_L7RSP;
|
||||
enum healthcheck_status tout_st = HCHK_STATUS_L7TOUT;
|
||||
long min_recv = -1;
|
||||
int inverse = 0, with_capture = 0;
|
||||
int inverse = 0;
|
||||
|
||||
str = on_success_msg = on_error_msg = comment = pattern = NULL;
|
||||
if (!*(args[cur_arg+1])) {
|
||||
@ -4203,25 +4177,6 @@ static struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, str
|
||||
cur_arg++;
|
||||
}
|
||||
|
||||
if (comment) {
|
||||
char *p = comment;
|
||||
|
||||
while (*p) {
|
||||
if (*p == '\\') {
|
||||
p++;
|
||||
if (!*p || !isdigit((unsigned char)*p) ||
|
||||
(*p == 'x' && (!*(p+1) || !*(p+2) || !ishex(*(p+1)) || !ishex(*(p+2))))) {
|
||||
memprintf(errmsg, "invalid backreference in 'comment' argument");
|
||||
goto error;
|
||||
}
|
||||
with_capture = 1;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
if (with_capture && !inverse)
|
||||
memprintf(errmsg, "using backreference in a positive expect comment is useless");
|
||||
}
|
||||
|
||||
chk = calloc(1, sizeof(*chk));
|
||||
if (!chk) {
|
||||
memprintf(errmsg, "out of memory");
|
||||
@ -4234,7 +4189,6 @@ static struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, str
|
||||
chk->expect.type = type;
|
||||
chk->expect.min_recv = min_recv;
|
||||
chk->expect.flags |= (inverse ? TCPCHK_EXPT_FL_INV : 0);
|
||||
chk->expect.flags |= (with_capture ? TCPCHK_EXPT_FL_CAP : 0);
|
||||
chk->expect.ok_status = ok_st;
|
||||
chk->expect.err_status = err_st;
|
||||
chk->expect.tout_status = tout_st;
|
||||
@ -4278,7 +4232,7 @@ static struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, str
|
||||
case TCPCHK_EXPECT_REGEX_BINARY:
|
||||
case TCPCHK_EXPECT_HTTP_REGEX_STATUS:
|
||||
case TCPCHK_EXPECT_HTTP_REGEX_BODY:
|
||||
chk->expect.regex = regex_comp(pattern, 1, with_capture, errmsg);
|
||||
chk->expect.regex = regex_comp(pattern, 1, 0, errmsg);
|
||||
if (!chk->expect.regex)
|
||||
goto error;
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user