Skip to content

Commit 2d116c1

Browse files
pedrosousaharshil1712
authored andcommitted
[Ruleset Engine] Use Types component in functions reference (#18143)
1 parent 954e2fa commit 2d116c1

File tree

1 file changed

+50
-27
lines changed

1 file changed

+50
-27
lines changed

src/content/docs/ruleset-engine/rules-language/functions.mdx

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ head:
88
content: Functions reference
99
---
1010

11+
import { Type, MetaInfo } from "~/components";
12+
1113
The Cloudflare Rules language provides functions for manipulating and validating values in an expression:
1214

1315
- [Transformation functions](#transformation-functions) manipulate values extracted from an HTTP request.
@@ -31,7 +33,8 @@ The Rules language supports these transformation functions:
3133

3234
### `any`
3335

34-
`any(Array<Boolean>)``Boolean`
36+
{/* prettier-ignore */}
37+
<code>any(<Type text="Array<Boolean>" />)</code>: <Type text="Boolean" />
3538

3639
Returns `true` when the comparison operator in the argument returns `true` for _any_ of the values in the argument array. Returns `false` otherwise.
3740

@@ -43,7 +46,8 @@ any(url_decode(http.request.body.form.values[*])[*] contains "an xss attack")
4346

4447
### `all`
4548

46-
`all(Array<Boolean>)``Boolean`
49+
{/* prettier-ignore */}
50+
<code>all(<Type text="Array<Boolean>" />)</code>: <Type text="Boolean" />
4751

4852
Returns `true` when the comparison operator in the argument returns `true` for _all_ values in the argument array. Returns `false` otherwise.
4953

@@ -55,7 +59,8 @@ all(http.request.headers["content-type"][*] == "application/json")
5559

5660
### `cidr`
5761

58-
`cidr(address (IP address), ipv4_network_bits (Integer), ipv6_network_bits (Integer))``IP address`
62+
{/* prettier-ignore */}
63+
<code>cidr(address <Type text="IP address" />, ipv4_network_bits <Type text="Integer" />, ipv6_network_bits <Type text="Integer" />)</code>: <Type text="IP address" />
5964

6065
Returns the network address corresponding to an IP address (IPv4 or IPv6), given the provided IPv4 and IPv6 network bits (which determine the corresponding netmasks).
6166

@@ -74,7 +79,8 @@ You can only use the `cidr()` function in [custom rules](/waf/custom-rules/) and
7479

7580
### `cidr6`
7681

77-
`cidr6(address (IP address), ipv6_network_bits (Integer))``IP address`
82+
{/* prettier-ignore */}
83+
<code>cidr6(address <Type text="IP address" />, ipv6_network_bits <Type text='Integer' />)</code>: <Type text="IP address" />
7884

7985
Returns the IPv6 network address corresponding to an IPv6 address, given the provided network bits (which determine the netmask). If you provide an IPv4 address in the first parameter, it will be returned unchanged.
8086

@@ -95,15 +101,17 @@ You can only use the `cidr6()` function in [custom rules](/waf/custom-rules/) an
95101

96102
### `concat`
97103

98-
`concat(String | Integer | Bytes | Array elements)``String`
104+
{/* prettier-ignore */}
105+
<code>concat(<Type text="String | Integer | Bytes | Array elements" />)</code>: <Type text="String" />
99106

100107
Takes a comma-separated list of values. Concatenates the argument values into a single String.
101108

102109
For example, `concat("String1", " ", "String", 2)` will return `"String1 String2"`.
103110

104111
### `decode_base64`
105112

106-
`decode_base64(source (String))``String`
113+
{/* prettier-ignore */}
114+
<code>decode_base64(source <Type text="String" />)</code>: <Type text="String" />
107115

108116
Decodes a Base64-encoded String specified in `source`.
109117

@@ -117,23 +125,26 @@ You can only use the `decode_base64()` function in [header modification rules](/
117125

118126
### `ends_with`
119127

120-
`ends_with(source (String), substring (String))``Boolean`
128+
{/* prettier-ignore */}
129+
<code>ends_with(source <Type text="String" />, substring <Type text="String" />)</code>: <Type text="Boolean" />
121130

122131
Returns `true` when the source ends with a given substring. Returns `false` otherwise. The source cannot be a literal value (like `"foo"`).
123132

124133
For example, if `http.request.uri.path` is `"/welcome.html"`, then `ends_with(http.request.uri.path, ".html")` will return `true`.
125134

126135
### `len`
127136

128-
`len(String | Bytes)``Integer`
137+
{/* prettier-ignore */}
138+
<code>len(<Type text="String | Bytes" />)</code>: <Type text="Integer" />
129139

130140
Returns the byte length of a String or Bytes field.
131141

132142
For example, if `http.host` is `"example.com"`, then `len(http.host)` will return `11`.
133143

134144
### `lookup_json_integer`
135145

136-
`lookup_json_integer(field (String), key (String | Integer) [, key (String | Integer), ...])``Integer`
146+
{/* prettier-ignore */}
147+
<code>lookup_json_integer(field <Type text="String" />, key <Type text="String | Integer" />, key <Type text="String | Integer" /> <MetaInfo text='optional' />, ...)</code>: <Type text="Integer" />
137148

138149
Returns the integer value associated with the supplied `key` in `field`.
139150

@@ -167,7 +178,8 @@ Examples:
167178

168179
### `lookup_json_string`
169180

170-
`lookup_json_string(field (String) key (String | Integer) [, key (String | Integer), ...])``String`
181+
{/* prettier-ignore */}
182+
<code>lookup_json_string(field <Type text="String" />, key <Type text="String | Integer" />, key <Type text="String | Integer" /> <MetaInfo text='optional' />, ...)</code>: <Type text="String" />
171183

172184
Returns the string value associated with the supplied `key` in `field`.
173185

@@ -199,15 +211,17 @@ Examples:
199211

200212
### `lower`
201213

202-
`lower(String)``String`
214+
{/* prettier-ignore */}
215+
<code>lower(<Type text="String" />)</code>: <Type text="String" />
203216

204217
Converts a string field to lowercase. Only uppercase ASCII bytes are converted. All other bytes are unaffected.
205218

206219
For example, if `http.host` is `"WWW.cloudflare.com"`, then `lower(http.host) == "www.cloudflare.com"` will return `true`.
207220

208221
### `regex_replace`
209222

210-
`regex_replace(source (String), regular_expression (String), replacement (String))``String`
223+
{/* prettier-ignore */}
224+
<code>regex_replace(source <Type text="String" />, regular_expression <Type text="String" />, replacement <Type text="String" />)</code>: <Type text="String" />
211225

212226
Replaces a part of a source string matched by a regular expression with a replacement string, returning the result. The replacement string can contain references to regular expression capture groups (for example, `${1}` and `${2}`), up to eight replacement references.
213227

@@ -239,23 +253,26 @@ You can only use the `regex_replace()` function in rewrite expressions of [Trans
239253

240254
### `remove_bytes`
241255

242-
`remove_bytes(Bytes)``Bytes`
256+
{/* prettier-ignore */}
257+
<code>remove_bytes(<Type text="Bytes" />)</code>: <Type text="Bytes" />
243258

244259
Returns a new byte array with all the occurrences of the given bytes removed.
245260

246261
For example, if `http.host` is `"www.cloudflare.com"`, then `remove_bytes(http.host, "\x2e\x77")` will return `"cloudflarecom"`.
247262

248263
### `starts_with`
249264

250-
`starts_with(source (String), substring (String))``Boolean`
265+
{/* prettier-ignore */}
266+
<code>starts_with(source <Type text="String" />, substring <Type text="String" />)</code>: <Type text="Boolean" />
251267

252268
Returns `true` when the source starts with a given substring. Returns `false` otherwise. The source cannot be a literal value (like `"foo"`).
253269

254270
For example, if `http.request.uri.path` is `"/blog/first-post"`, then `starts_with(http.request.uri.path, "/blog")` will return `true`.
255271

256272
### `substring`
257273

258-
`substring(field (String | Bytes), start (Integer) [, end (Integer)])``String`
274+
{/* prettier-ignore */}
275+
<code>substring(field <Type text="String | Bytes" />, start <Type text="Integer" />, end <Type text="Integer" /> <MetaInfo text='optional' />)</code>: <Type text="String" />
259276

260277
Returns part of the `field` value (the value of a String or Bytes [field](/ruleset-engine/rules-language/fields/)) from the `start` byte index up to (but excluding) the `end` byte index. The first byte in `field` has index `0`. If you do not provide the optional `end` index, the function returns the part of the string from `start` index to the end of the string.
261278

@@ -274,7 +291,8 @@ substring(http.request.body.raw, 0, -2) will return "asdfgh"
274291

275292
### `to_string`
276293

277-
`to_string(Integer | Boolean | IP address)``String`
294+
{/* prettier-ignore */}
295+
<code>to_string(<Type text="Integer | Boolean | IP address" />)</code>: <Type text="String" />
278296

279297
Returns the string representation of an Integer, Boolean, or IP address value.
280298

@@ -294,15 +312,17 @@ You can only use the `to_string()` function in rewrite expressions of [Transform
294312

295313
### `upper`
296314

297-
`upper(String)``String`
315+
{/* prettier-ignore */}
316+
<code>upper(<Type text="String" />)</code>: <Type text="String" />
298317

299318
Converts a string field to uppercase. Only lowercase ASCII bytes are converted. All other bytes are unaffected.
300319

301320
For example, if `http.host` is`"www.cloudflare.com"`, then `upper(http.host)` will return `"WWW.CLOUDFLARE.COM"`.
302321

303322
### `url_decode`
304323

305-
`url_decode(source (String)[, options (String)])``String`
324+
{/* prettier-ignore */}
325+
<code>url_decode(source <Type text="String" />, options <Type text="String" /> <MetaInfo text='optional' />)</code>: <Type text="String" />
306326

307327
Decodes a URL-formatted string defined in `source`, as in the following:
308328

@@ -331,7 +351,8 @@ any(url_decode(http.request.body.form.values[*])[*] contains "an xss attack")
331351

332352
### `uuidv4`
333353

334-
`uuidv4(Bytes)``String`
354+
{/* prettier-ignore */}
355+
<code>uuidv4(source <Type text="Bytes" />)</code>: <Type text="String" />
335356

336357
Generates a random UUIDv4 (Universally Unique Identifier, version 4) based on the given argument (a source of randomness). To obtain an array of random bytes, use the [`cf.random_seed`](/ruleset-engine/rules-language/fields/dynamic-fields/#cfrandom_seed) field.
337358

@@ -343,7 +364,8 @@ You can only use the `uuidv4()` function in [rewrite expressions of Transform Ru
343364

344365
### `wildcard_replace`
345366

346-
`wildcard_replace(source (Bytes), wildcard_pattern (Bytes), replacement (Bytes) [, flags (Bytes)])``String`
367+
{/* prettier-ignore */}
368+
<code>wildcard_replace(source <Type text="Bytes" />, wildcard_pattern <Type text="Bytes" />, replacement <Type text="Bytes" />, flags <Type text="Bytes" /> <MetaInfo text='optional' />)</code>: <Type text="String" />
347369

348370
Replaces a `source` string, matched by a literal with zero or more `*` wildcard metacharacters, with a replacement string, returning the result. The replacement string can contain references to wildcard capture groups (for example, `${1}` and `${2}`), up to eight replacement references.
349371

@@ -389,7 +411,8 @@ Currently, you can only use the `wildcard_replace()` function in rewrite express
389411

390412
### `bit_slice`
391413

392-
`bit_slice(protocol (String), offset_start (Number), offset_end (Number))``Number`
414+
{/* prettier-ignore */}
415+
<code>bit_slice(protocol <Type text="String" />, offset_start <Type text="Number" />, offset_end <Type text="Number" />)</code>: <Type text="Number" />
393416

394417
This function looks for matches on a given slice of bits.
395418

@@ -424,27 +447,27 @@ is_timed_hmac_valid_v0(
424447

425448
The `is_timed_hmac_valid_v0()` function has these parameter definitions:
426449

427-
- `Key` (String literal)
450+
- `Key` <Type text="String literal" />
428451

429452
- Specifies the secret cryptographic key for validating the HMAC.
430453

431-
- `MessageMAC` (String)
454+
- `MessageMAC` <Type text="String" />
432455

433456
- Contains a concatenation of these HMAC elements: `message`, `separator`, `timestamp`, `mac`. For a definition and an example, refer to [MessageMAC](#messagemac).
434457

435-
- `ttl` (Integer literal)
458+
- `ttl` <Type text="Integer literal" />
436459

437460
- Defines the time-to-live for the HMAC token, expressed in seconds. Determines how long the token is valid, relative to the time it was issued.
438461

439-
- `currentTimeStamp` (Integer)
462+
- `currentTimeStamp` <Type text="Integer" />
440463

441464
- Represents the UNIX timestamp when Cloudflare received the request, expressed in seconds. Pass the `http.request.timestamp.sec` field as an approximate value to this argument.
442465

443-
- `lengthOfSeparator` (Integer literal, optional)
466+
- `lengthOfSeparator` <Type text="Integer literal" /> <MetaInfo text='optional' />
444467

445468
- Specifies the length of the `separator` between the `timestamp` and the `message` in the `MessageMAC`. Expressed in bytes, with a default value of `0`.
446469

447-
- `flags` (String literal, optional)
470+
- `flags` <Type text="String literal" /> <MetaInfo text='optional' />
448471

449472
- When you set this optional argument to `'s'`, the function expects the value of the Base64-encoded `mac` in the `MessageMAC` argument to use the URL-safe character set with no padding.
450473

0 commit comments

Comments
 (0)