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"
This commit is contained in:
Aurelien DARRAGON 2022-12-30 16:23:08 +01:00 committed by Christopher Faulet
parent 82faad1069
commit 5c6f86f465
2 changed files with 25 additions and 0 deletions

View File

@ -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(<value>)
Adds <value> to the input value of type signed integer, and returns the
result as a signed integer. <value> can be a numeric value or a variable

View File

@ -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 <const> 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 },
}};