Class GuardRuleEngine
java.lang.Object
org.frontcache.guard.GuardRuleEngine
Runs the guard rules for every request, before cache and origin.
Rules are evaluated in order, first match wins:
1. built-ins (uri-too-long, bad-request) - always first, they are the structural checks
2. rules from FRONTCACHE_HOME/conf/guard-rules.conf, in file order
The rule list is global - there is no per-domain guard-rules.conf (a rule targets a domain with
a host~ predicate). Guards run on the request thread for every request, so evaluate() is written
to allocate nothing on the common no-match path and to never throw: any unexpected failure is
logged and treated as "no match", leaving Frontcache behaving exactly as it does without guards.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionevaluate(RequestContext context) Runs the rules for one request.getRules()voidreload()Re-reads guard-rules.conf.Dry-parses a candidate guard-rules.conf without touching anything live, for theset-configmanagement action.
-
Field Details
-
GUARD_RULES_CONFIG_FILE
- See Also:
-
RULE_URI_TOO_LONG
- See Also:
-
RULE_BAD_REQUEST
- See Also:
-
-
Constructor Details
-
GuardRuleEngine
public GuardRuleEngine(int maxRequestURILength)
-
-
Method Details
-
reload
public void reload()Re-reads guard-rules.conf. Built-ins are rebuilt too, so a changed front-cache.max-request-uri-length is picked up by the next FrontCacheEngine reload. -
getRules
-
validate
Dry-parses a candidate guard-rules.conf without touching anything live, for theset-configmanagement action. Nothing here mutates state. No rule swap, noClientIpResolver.reload(), no hit counters reset, no rate-limit buckets bound to the live registry - the parsed rules are thrown away. The allowlist used is the live one, which is correct: it comes from frontcache.properties, not from the file being edited.- Returns:
- one message per unusable line,
"line N: ...", in file order; empty when the whole file parses
-
evaluate
Runs the rules for one request. Never throws.- Returns:
- a terminal outcome (reject/redirect) or CONTINUE, carrying any dry-run rules that matched so the caller can log them
-