http-var #
ngx_http_var_module is a nginx module that dynamically assigns new variables through predefined functions.
Source: upstream source
Directives
var #
syntax: var $new_variable function [-i] args... [if\=condition] · default: - · context: http, server, location
Define a new variable whose value is the result of function calculation. The variable value cannot be cached and is recalculated each time it is used. If the current level does not define a variable with the same variable name, it can be inherited from the previous level. The -i parameter is used to ignore case (Available only in some functions).
Example
#### Conditional Judgement ####
# Returns 1 if the input parameter is empty or 0, otherwise returns 0
var $bool_var not str;
# Returns 1 if all input parameters are non-empty and not 0, otherwise returns 0
var $bool_var and str1 str2...;
# Returns 1 if any input parameter is non-empty and not 0, otherwise returns 0
var $bool_var or str1 str2...;
#### String Judgement ####
# Checks if the string is empty, returns 1 or 0
var $bool_var is_empty str;
# Checks if the string is non-empty, returns 1 or 0
var $bool_var is_not_empty str;
# Checks if the string is a number, returns 1 or 0. Only decimal numbers are allowed. negative numbers and fractions are supported.
var $bool_var is_num str;
# Checks if the strings are equal, returns 1 or 0
var $bool_var str_eq [-i] str1 str2;
# Checks if the strings are not equal, returns 1 or 0
var $bool_var str_ne [-i] str1 str2;
# Checks if the string has the specified prefix, returns 1 or 0
var $bool_var starts_with [-i] str prefix;
# Checks if the string has the specified suffix, returns 1 or 0
var $bool_var ends_with [-i] str suffix;
# Checks if the substring is present, returns 1 or 0
var $bool_var contains [-i] str sub_str;
# Checks if the str1 is one of str2 .. strn, returns 1 or 0
var $bool_var str_in [-i] str1 str2 str3 .. strn;
#### General String Operations ####
# Set the value directly of the variable
var $new_var set src_str;
# Length of the string
var $new_var len src_str;
# Convert to uppercase
var $new_var upper src_str;
# Convert to lowercase
var $new_var lower src_str;
# Capitalize the first letter of each word (words are separated by non-alphanumeric characters)
var $new_var initcap src_str;
# Trim leading and trailing whitespace characters or other characters
var $new_var trim src_str [char];
# Trim leading whitespace characters or other characters
var $new_var ltrim src_str [char];
# Trim trailing whitespace characters or other characters
var $new_var rtrim src_str [char];
# Reverse the string
var $new_var reverse src_str;
# Get starting position of substring
var $new_var position [-i] src_str sub_str;
# Repeat the string a given number of times
var $new_var repeat src_str times;
# Extract substring
var $new_var substr src_str start [len];
# Replace keyword
var $new_var replace [-i] src_str src dst;
# Extract parameters
# Extract a value from a list of parameters. A use case for th
…