All Products
Search
Document Center

Edge Security Acceleration:Miscellaneous functions

Last Updated:Jun 16, 2026

Miscellaneous functions provide Base64 encoding and decoding, URL encoding and decoding, random number generation, CRC calculation, and type conversion.

base64_enc

Details:
Item Description
Syntax base64_enc(s [, no_padding])
Feature Encodes a string in Base64.
Parameter
  • s: the string that you want to encode.
  • no_padding: specifies whether to disable padding. A value of true disables padding. Default value: false.
Return value Returns a Base64-encoded string.
Example
if $http_data {
 decdata = base64_dec($http_data)
 say(concat('base64_decdata=', decdata))
 say(concat('base64_encdata=', base64_enc('hello, dsl'))) 
}
  • Request header:
    "data: aGVsbG8sIGRzbA=="
  • Response:
    base64_decdata=hello, dsl
    base64_encdata=aGVsbG8sIGRzbA==

base64_dec

Details:
Item Description
Syntax base64_dec(s)
Feature Decodes a Base64-encoded string.
Parameter s: the string that you want to decode.
Return value Returns a decoded raw string.
Example
if $http_data {
 decdata = base64_dec($http_data)
 say(concat('base64_decdata=', decdata))
 say(concat('base64_encdata=', base64_enc('hello, dsl'))) 
}
  • Request header:
    "data: aGVsbG8sIGRzbA=="
  • Response:
    base64_decdata=hello, dsl
    base64_encdata=aGVsbG8sIGRzbA==

url_escape

Details:
Item Description
Syntax url_escape(s)
Feature URL-encodes a string.
Parameter s: the string that you want to encode.
Return value Returns a URL-encoded string.
Example
raw = '/abc/123/ dd/file.m3u8'
esdata = url_escape(raw)
dsdata = url_unescape(esdata)
if eq(raw, dsdata) {
  say(concat('raw=', raw))
  say(concat('dsdata=', dsdata))
}
Output:
raw=/abc/123/ dd/file.m3u8
esdata=%2Fabc%2F123%2F%20dd%2Ffile.m3u8
dsdata=/abc/123/ dd/file.m3u8

url_unescape

Details:
Item Description
Syntax url_unescape(s)
Feature Decodes a URL-encoded string.
Parameter s: the string that you want to decode.
Return value Returns a decoded raw string.
Example
raw = '/abc/123/ dd/file.m3u8'
esdata = url_escape(raw)
dsdata = url_unescape(esdata)
if eq(raw, dsdata) {
  say(concat('raw=', raw))
  say(concat('dsdata=', dsdata))
}
Output:
raw=/abc/123/ dd/file.m3u8
esdata=%2Fabc%2F123%2F%20dd%2Ffile.m3u8
dsdata=/abc/123/ dd/file.m3u8

rand

Details:
Item Description
Syntax rand(n1, n2)
Feature Generates a random number in the range n1 <= returned number <= n2.
Parameter
  • n1: the minimum value.
  • n2: the maximum value.
Return value Returns a random number.
Example
r = rand(1,100)

rand_hit

Details:
Item Description
Syntax rand_hit(ratio)
Feature Returns true or false based on the specified probability.
Parameter ratio: the probability. Valid values: 0 to 100.
Return value Returns true or false based on the specified probability. A ratio of 100 always returns true. A ratio of 0 always returns false.
Example
rand_hit(80)

crc

Details:
Item Description
Syntax crc(s)
Feature Calculates a Cyclic Redundancy Check (CRC) value.
Parameter s: the string for which to calculate a CRC digest.
Return value Returns the CRC value of the string specified by s.
Example
crc('hello edgescript')

tonumber

Details:
Item Description
Syntax tonumber(s [, base])
Feature Converts a string to a number.
Parameter
  • s: the string to convert.
  • base: the numeral system for conversion. Valid values: 10 and 16. Default value: 10.
Example
n = tonumber('100')
say(concat('tonumber()=', n))
Output:
tonumber()=100

base64_enc_safe

Details:
Item Description
Syntax base64_enc_safe(str)
Feature Encodes a string in URL-safe Base64. In the output, plus signs (+) are replaced by minus signs (-), forward slashes are replaced by underscores (_), and padding equal signs (=) are removed.
Parameter str: the string that you want to encode.
Return value Returns a URL-safe Base64-encoded string.
Example
add_rsp_header('X-RESPOND-OUTPUT', concat('base64_enc_safe=', base64_enc_safe('hello, dsl')), true)
Response header:
X-RESPOND-OUTPUT: base64_enc_safe=aGVsbG8sIGRzbA

base64_dec_safe

Details:
Item Description
Syntax base64_dec_safe(str)
Feature Decodes a URL-safe Base64-encoded string. During decoding, minus signs (-) are replaced by plus signs (+) and underscores (_) are replaced by forward slashes (/). Padding equal signs (=) are appended to ensure the string length is a multiple of four.
Parameter str: the URL-safe Base64-encoded string to decode.
Return value Returns a decoded raw string.
Example
add_rsp_header('X-RESPOND-OUTPUT', concat('base64_dec_safe=', base64_dec_safe(base64_enc_safe('hello, dsl'))), true)
Response header:
X-RESPOND-OUTPUT:base64_dec_safe=hello, dsl

randomseed

Details:
Item Description
Syntax randomseed()
Feature Generates a random seed.
Parameter N/A
Return value N/A.
Example
randomseed()
r = rand(1,100)