- Author
Dridi Boukelmoune
- Date
2012-06-18
- Version
0.3
- Manual section
3
import querystring;
Varnish multipurpose vmod for URI query-string manipulation. Can be used to normalize for instance request URLs or Location response headers in various ways. It is recommended to at least clean incoming request URLs (removing empty parameters or query-strings), all other functions do the cleaning.
- Prototype
STRING clean(STRING url)
- Description
Returns the given URI without empty parameters. The query-string is removed if empty (either before or after the removal of empty parameters).
- Example
set req.url = querystring.clean(req.url);
- Prototype
STRING remove(STRING url)
- Description
Returns the given URI with its query-string removed
- Example
set req.url = querystring.remove(req.url);
- Prototype
STRING sort(STRING url)
- Description
Returns the given URI with its query-string sorted
- Example
set req.url = querystring.sort(req.url);
- Prototype
STRING filtersep()
- Description
Returns the separator needed by the filter and filter_except functions
- Prototype
STRING filter(STRING url, STRING_LIST parameter_names)
- Description
Returns the given URI without the listed parameters
- Example
- set req.url = querystring.filter(req.url,
"utm_source" + querystring.filtersep() + "utm_medium" + querystring.filtersep() + "utm_campaign");
- Prototype
STRING filter_except(STRING url, STRING_LIST parameter_names)
- Description
Returns the given URI but only keeps the listed parameters
- Example
- set req.url = querystring.filter_except(req.url,
"q" + querystring.filtersep() + "p");
- Prototype
STRING regfilter(STRING url, STRING parameter_names_regex)
- Description
Returns the given URI without the parameters matching a regular expression
- Example
set req.url = querystring.regfilter(req.url, "utm_.*");
- Prototype
STRING regfilter_except(STRING url, STRING parameter_names_regex)
- Description
Returns the given URI but only keeps the parameters matching a regular expression
- Example
set req.url = querystring.regfilter_except(req.url, "^(q|p)$");
In your VCL you could then use this vmod along the following lines:
import querystring;
sub vcl_hash {
# sort the URL before the request hashing
set req.url = querystring.sort(req.url);
}
The sort algorithm is a mix of Jason Mooberry's Skwurly and my own QuerySort with regards for the Varnish workspace memory model of the worker threads.
This document is licensed under the same license as the libvmod-querystring project. See LICENSE for details.
- Copyright (c) 2012-2014 Dridi Boukelmoune