Unify the expression of conditions so that:
- no VCL code has to be written
- we can reason to find out which condition is more specific (they should be evaluated first)
- we can aggregate and combine conditions.
Basic Boolean logic:
Property Matching:
url
referer
client_name
client_city
client_country_code
user_agent
accept_language
url_param.<name>
All property matching is using substring-starts
, so only substring matches starting at index 0 are considered. More concise matching operations can be enabled through the suffixes: url=
(strict match) and url~
(regex match)
Property Ranges:
client_lat>
, client_lat<
, client_lon>
, client_lon<
Suggestion
1 Alternatively, use a visitor pattern.
Notes
We would have a new Condition
class that adds following functions:
toFunction
: creates a Javascript function that evaluates the condition against an express-style request object
toVCL
: generates a VCL snippet
We can then further subdivide it into PropertyCondition
and BooleanCondition
. PropertyCondition
simply has two properties: property
and condition
and two private mapping tables of property
to JavaScript function and property
to VCL string.
BooleanCondition
has a list of children
and an internal mapping table for the prefix, suffix, and infix (e.g. !
is a prefix, and &&
is an infix)
Appendix A
Support to calculate base-url
For conditions that select a strain based on URL, it is important to determine the common root path of the URL that matched the request. this base-url acts as chroot for resource processing.
Examples:
condition |
request (path) |
base-url (path) |
url: https://www.adobe.com |
n/a |
`` |
url: https://www.adobe.com/ |
n/a |
`` |
url: https://www.adobe.com/api/docs |
n/a |
/api/docs |
url~: https://www.adobe.com/[^/]+/docs |
/client/docs/index.html |
/client/docs |
(the regexp support might be an advanced feature...)
So it might be better to return a ConditionResult
from toFunction()(req)
that contains some method to determine the base url. eg:
const res = strain.getCondition().match(req);
if (res) {
const baseUrl = res.getBaseUrl();
...
}
for VCL, the condition should be able to produce a script that calculates the baseURL.