port_only string integer
protobuf(field_number[,field_type]) binary binary
regsub(regex,subst[,flags]) string string
+reverse string string
rfc7239_field(field) string string
rfc7239_is_valid string boolean
rfc7239_n2nn string address / str
http-request redirect location %[url,'regsub("(foo|bar)([0-9]+)?","\2\1",i)']
http-request redirect location %[url,regsub(\"(foo|bar)([0-9]+)?\",\"\2\1\",i)]
+reverse
+ Reverses the input string byte by byte.
+
+ This converter is encoding-agnostic and reverses bytes, not characters; it is
+ not suitable for reversing human text encoded as UTF-8.
+
+ This can turn suffix lookups on the original string into prefix lookups on
+ the reversed string, allowing the use of indexed prefix matchers such as
+ "map_beg" on large maps.
+
+ Examples:
+ "example.com" -> "moc.elpmaxe"
+ "ab cd" -> "dc ba"
+
+ # Given a map file where each key contains a reversed hostname:
+ # moc.elpmaxe.ppa app1
+ # moc.elpmaxe.bd dbcluster
+ # Pick a backend based on the domain suffix of the Host header:
+ use_backend %[req.hdr(host),lower,reverse,map_beg(/etc/haproxy/hosts.map,default)]
+
rfc7239_field(<field>)
Extracts a single field/parameter from RFC 7239 compliant header value input.
--- /dev/null
+varnishtest "reverse converter test"
+
+feature ignore_unknown_macro
+
+server s1 {
+ rxreq
+ txresp -hdr "Connection: close"
+} -repeat 4 -start
+
+haproxy h1 -conf {
+ global
+ .if feature(THREAD)
+ thread-groups 1
+ .endif
+
+ defaults
+ mode http
+ timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+ timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
+ timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
+
+ frontend fe
+ bind "fd@${fe}"
+
+ http-request return status 200 hdr X-Reverse "%[str(example.com),reverse]" hdr X-Reverse2 "%[str(ab cd),reverse]" hdr X-Reverse3 "%[str(example.com),reverse,concat(.)]" hdr X-Reverse4 "%[str(),reverse]"
+
+ default_backend be
+
+ backend be
+ server s1 ${s1_addr}:${s1_port}
+} -start
+
+client c1 -connect ${h1_fe_sock} {
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.x-reverse == "moc.elpmaxe"
+ expect resp.http.x-reverse2 == "dc ba"
+ expect resp.http.x-reverse3 == "moc.elpmaxe."
+ expect resp.http.x-reverse4 == "<undef>"
+} -run
return 1;
}
+/* Reverses the input string byte by byte. */
+static int sample_conv_reverse(const struct arg *arg_p, struct sample *smp, void *private)
+{
+ const char *input = smp->data.u.str.area;
+ struct buffer *trash;
+ int input_len = smp->data.u.str.data;
+ int i;
+
+ trash = get_trash_chunk_sz(input_len + 1);
+ if (!trash)
+ return 0;
+
+ for (i = 0; i < input_len; i++)
+ trash->area[i] = input[input_len - 1 - i];
+
+ trash->area[input_len] = 0;
+ trash->data = input_len;
+ smp->data.u.str = *trash;
+ smp->data.type = SMP_T_STR;
+ smp->flags &= ~SMP_F_CONST;
+ return 1;
+}
+
/* takes the IPv4 mask in args[0] and an optional IPv6 mask in args[1] */
static int sample_conv_ipmask(const struct arg *args, struct sample *smp, void *private)
{
{ "strcmp", sample_conv_strcmp, ARG1(1,STR), smp_check_strcmp, SMP_T_STR, SMP_T_SINT },
{ "host_only", sample_conv_host_only, 0, NULL, SMP_T_STR, SMP_T_STR },
{ "port_only", sample_conv_port_only, 0, NULL, SMP_T_STR, SMP_T_SINT },
+ { "reverse", sample_conv_reverse, 0, NULL, SMP_T_STR, SMP_T_STR },
/* gRPC converters. */
{ "ungrpc", sample_conv_ungrpc, ARG2(1,PBUF_FNUM,STR), sample_conv_protobuf_check, SMP_T_BIN, SMP_T_BIN },