From: Aurelien DARRAGON Date: Fri, 30 Dec 2022 15:23:08 +0000 (+0100) Subject: MINOR: http_ext: add rfc7239_is_valid converter X-Git-Tag: v2.8-dev3~69 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5c6f86f465b79536fc0ceb2a4740fbcbb6dbab71;p=thirdparty%2Fhaproxy.git MINOR: http_ext: add rfc7239_is_valid converter Adding new http converter: rfc7239_is_valid. Takes a string representing 7239 forwarded header single value as input and returns bool:TRUE if header is RFC compliant and bool:FALSE otherwise. Example: acl valid req.hdr(forwarded),rfc7239_is_valid #input: "for=127.0.0.1;proto=http" # output: TRUE #input: "proto=custom" # output: FALSE Depends on: - "MINOR: http_ext: introduce http ext converters" --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 2d70047f0c..a40f0903fb 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -17217,6 +17217,17 @@ The currently available list of transformation keywords include : http-request set-header X-51D-DeviceTypeMobileTablet \ %[req.fhdr(User-Agent),51d.single(DeviceType,IsMobile,IsTablet)] +rfc7239_is_valid + Returns true if input header is RFC 7239 compliant header value and false + otherwise. + + Example: + acl valid req.hdr(forwarded),rfc7239_is_valid + #input: "for=127.0.0.1;proto=http" + # output: TRUE + #input: "proto=custom" + # output: FALSE + add() Adds to the input value of type signed integer, and returns the result as a signed integer. can be a numeric value or a variable diff --git a/src/http_ext.c b/src/http_ext.c index 1c621a66a7..1b899471cb 100644 --- a/src/http_ext.c +++ b/src/http_ext.c @@ -1370,8 +1370,22 @@ void http_ext_xot_copy(struct http_ext_xot *dest, const struct http_ext_xot *ori * related converters */ +/* input: string representing 7239 forwarded header single value + * does not take arguments + * output: 1 if header is RFC compliant, 0 otherwise + */ +static int sample_conv_7239_valid(const struct arg *args, struct sample *smp, void *private) +{ + struct ist input = ist2(smp->data.u.str.area, smp->data.u.str.data); + + smp->data.type = SMP_T_BOOL; + smp->data.u.sint = !!http_validate_7239_header(input, FORWARDED_HEADER_ALL, NULL); + return 1; +} + /* Note: must not be declared as its list will be overwritten */ static struct sample_conv_kw_list sample_conv_kws = {ILH, { + { "rfc7239_is_valid", sample_conv_7239_valid, 0, NULL, SMP_T_STR, SMP_T_BOOL}, { NULL, NULL, 0, 0, 0 }, }};