Search
Varnish Enterprise

Introduction Installation Upgrading Troubleshooting Changelog Changelog for 6.0.x Changes (Varnish Cache 4.1) Changes (Varnish Cache Plus 4.1) Known Issues Features Backend SSL/TLS Client SSL/TLS termination Cluster In-Process TLS MSE 4 Basic Configuration / Getting Started Configuration Persisted caching Categories Configuration Reference MSE 3.0 Settings mkfs.mse Memory Governor MSE 2.0 NUMA Parallel ESI Backend health counter HTTP/2 Support JSON Logging TCP Only Probes Timeouts Transit Buffer Varnish scoreboard VMODs Accept Accounting ACL (aclplus) ActiveDNS Akamai Connector AWS VCL Body Access & Transformation (xbody) Brotli Cookie Plus (cookieplus) DeviceAtlas DeviceAtlas3 Digest Dynamic backends (goto) Edgestash File Format Geolocation (geoip/mmdb) Header Manipulation (headerplus) HTTP communication (http) Image JSON parsing (json) JWT Key value storage (kvstore) Least connections director (leastconn) Module to control the built-in HTTP2 transport (h2) MSE control (mse) MSE4 control (mse4) Probe Proxy ProxyV2 TLV Attribute Extraction (proxy) Pseudo Random Number Generator Purge (purge/softpurge) Real-time Status (rtstatus) Reverse DNS (resolver) Rewrite S3 VMOD Session Slicer SQLite3 Stale Standard (std) Stat (Prometheus) Strings (str) Synthetic backends (synthbackend) Tag-based invalidation (Ykey/Xkey) TCP configuration (tcp) TLS Total Encryption (crypto) Unified director object (udo) Uniform Resource Identifier (uri) Unix Socket Utilities (unix) URL Plus (urlplus) Utils Vsthrottle

Strings (str)

Description

The string vmod implements various helper function to manipulate strings.

API

len

INT len(STRING S)

Returns the number of ascii characters in S, or -1 if S is null.

Arguments:

  • S accepts type STRING

Type: Function

Returns: Int

startswith

BOOL startswith(STRING S1, STRING S2)

Returns true if S1 starts with S2.

Arguments:

  • S1 accepts type STRING

  • S2 accepts type STRING

Type: Function

Returns: Bool

endswith

BOOL endswith(STRING S1, STRING S2)

Returns true if S1 ends with S2.

Arguments:

  • S1 accepts type STRING

  • S2 accepts type STRING

Type: Function

Returns: Bool

contains

BOOL contains(STRING S1, STRING S2)

Returns true if S1 contains S2.

Arguments:

  • S1 accepts type STRING

  • S2 accepts type STRING

Type: Function

Returns: Bool

substr

STRING substr(STRING S, INT N, INT OFFSET = 0)

Returns a substring that is at most abs(N) characters long, from the character at the OFFSET position (negative OFFSET counts from the back of the string). If N is positive, the substring is extracted right of OFFSET, left otherwise.

Example:

  • substr(“0123456789abcdef”, 2, 5) -> “56”, 2 characters from the 5th one
  • substr(“0123456789abcdef”, 2, -5) -> “be”, 2 characters from the 5th to last one
  • substr(“0123456789abcdef”, -2, 5) -> “45”, 2 characters to the 5th one
  • substr(“0123456789abcdef”, -2, -5) -> “ab”, 2 characters to the 5th to last one
  • substr(“0123456789abcdef”, 10, 20) -> “abcdef”, truncated because the end of the string was reached.

If S in NULL, NULL is returned.

Arguments:

  • S accepts type STRING

  • N accepts type INT

  • OFFSET accepts type INT with a default value of 0 optional

Type: Function

Returns: String

reverse

STRING reverse(STRING S)

Reverse S.

Arguments:

  • S accepts type STRING

Type: Function

Returns: String

split

STRING split(STRING S, INT n, STRING SEP = " \t")

Split s and return the N-th token (index starts at 1). Characters in SEP are separators. A negative N indicate “from the end of the string”. The value of “STRING SEP” can be multiple characters, the vmod will split the string at all of the given values.

Example:

  • split("/item_1.mp4|/item_2.mp4|/item_3/mp4", 1, “|”) -> “/item_1.mp4”, first item, | as a separator.
  • split("/item_1.mp4|/item_2.mp4|/item_3/mp4", -1, “|@”) -> “/item_3.mp4”, last item, | or @ as a separator.
  • split("/item_1.mp4@/item_2.mp4@/item_3/mp4", 2, “@”) -> “/item_2.mp4”, second item, @ as a seperator.
  • split("/item_1.mp4|/item_2.mp4@/item_3/mp4", -1, “|@”) -> “/item_3/mp4”, last item, @ or | as a separator.

Arguments:

  • S accepts type STRING

  • n accepts type INT

  • SEP accepts type STRING with a default value of \t optional

Type: Function

Returns: String

token_intersect

BOOL token_intersect(STRING str1, STRING str2, [STRING separators])

Checks if the set tokens in one string intersects the set of tokens in the other string. In other words, it returns true if there is a token which exists in both strings.

If the separators argument is not supplied, the space and comma characters are the separators. Empty tokens are ignored in both strings.

Arguments:

  • str1 accepts type STRING

  • str2 accepts type STRING

  • separators accepts type STRING

Type: Function

Returns: Bool

Availability

The str VMOD is available in Varnish Enterprise version 6.0.4r3 and later.


®Varnish Software, Wallingatan 12, 111 60 Stockholm, Organization nr. 556805-6203