Rules – Remove surrounding bytes with trim functions

Cloudflare Rules supports three new functions for removing surrounding bytes. Use them to remove whitespace before comparing request values. All HTTP products support these functions on all plans:

  • trim() removes bytes from both ends.
  • trim_start() removes bytes from the start.
  • trim_end() removes bytes from the end.

By default, these functions remove ASCII whitespace. An optional constant string specifies a custom set of bytes.

If the input value is nil, these functions return nil.

For example, this expression removes surrounding whitespace before comparing a header value:

trim(http.request.headers["x-label"][0]) eq "approved"

For details, refer to the trim(), trim_start(), and trim_end() function references.

Source: Cloudflare

Share This Update