Vmod-dbrw |
|
Database-driven rewrites for Varnish Cache |
Sergey Poznyakoff |
3.1 Expansions
The ‘query’ argument to the dbrw.config
function
normally contains variable references. A variable reference has the
form ‘$variable’ or ‘${variable}’, where
variable is the variable name. When the dbrw.rewrite
function (see Rewrite) is called, each such reference is expanded
to the actual value of variable passed in the argument to that
function.
The two forms are entirely equivalent. The form with curly braces is normally used if the variable name is immediately followed by an alphanumeric symbol, which will otherwise be considered a part of it. This form also allows for specifying the action to take if the variable is undefined or expands to an empty value.
During variable expansion, the forms below cause dbrw.rewrite
to test for a variable that is unset or null (i.e., whose value is an
empty string). Omitting the colon results in a test only for a
variable that is unset.
- ${variable:-word}
Use Default Values. If variable is unset or null, the expansion of word is substituted. Otherwise, the value of variable is substituted.
- ${variable:=word}
Assign Default Values. If variable is unset or null, the expansion of word is assigned to variable. The value of variable is then substituted.
- ${variable:?word}
Display Error if Null or Unset. If variable is null or unset, the expansion of word (or a message to that effect if word is not present) is output to the current logging channel. Otherwise, the value of variable is substituted.
- ${variable:+word}
Use Alternate Value. If variable is null or unset, nothing is substituted, otherwise the expansion of word is substituted.
After expanding variables, the query undergoes command expansion. Syntactically, a command invocation is
$(cmd args)
where cmd is the command name, and args is a list of arguments separated by whitespace. Arguments can in turn contain variable and command references.
During command expansion, each invocation is replaced by the result of the call to function cmd with the supplied arguments.
As of version 2.7 of vmod-dbrw
, only one
function is declared:
- Command: urlprefixes uri
Expands to comma-separated list of path prefixes contained in uri, starting from the longest one (uri itself, with eventual query part stripped off). Single ‘/’ is not included in the list. Each list item is quoted. The expansion can be used in the ‘IN ()’ SQL conditional.
This document was generated on April 9, 2020 using makeinfo.
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.