The domain_set plugin provides a flexible domain-matching dataset that other plugins can consume. It loads domain rules from files or inline expressions and exposes them via request metadata for fast lookups.
- Maintain lists of domains with different match semantics (exact, domain+subdomains, regex, keyword).
- Share precompiled domain sets with other plugins (the plugin writes an
Arc<RwLock<DomainRules>>into metadata keyed bydomain_set_<name>).
The plugin supports four match types. Evaluation priority is: Full > Domain > Regexp > Keyword.
full: exact case-insensitive match (such asfull:example.com). Does not match subdomains.domain: domain and all subdomains (such asdomain:example.commatchingexample.comandwww.example.com). This is the default match type.regexp: regular expression match (Rustregexsyntax). Patterns are compiled and evaluated in import order.keyword: substring match (case-insensitive). Rules evaluated in import order.
When multiple domain rules could match, the priority and domain specificity rules ensure deterministic behavior (more specific domain wins before less specific TLD rules).
Rules may be provided in files or inline via the exps argument (sequence or single string). Each non-comment line may be one of:
full:example.comdomain:example.comregexp:.+\.google\.com$keyword:googleexample.com(usesdefault_match_type, typicallydomain)
Lines starting with # are ignored. Leading/trailing whitespace is trimmed.
tag/ plugin name: used as the domain-set name if provided.files(string or sequence): paths to domain list files to load.exps(string or sequence): inline expressions to load.auto_reload(bool): enable file watcher to reload when files change (default: false).default_match_type/match_type(string): one offull,domain,regexp,keyword(default:domain).
Example configuration:
plugins:
- tag: cn-domains
type: domain_set
config:
files:
- examples/etc/my-domain-list.txt
auto_reload: true
default_match_type: domainOr inline expressions:
plugins:
- tag: sample-set
type: domain_set
config:
exps:
- full:exact.com
- domain:example.com
- regexp:.+\.github\.io$
- keyword:adsWhen the plugin executes, it stores the compiled DomainRules in request metadata under the key domain_set_<name> where <name> is the plugin tag or effective name. Other plugins implementing Matcher can read this metadata and call into it.
- Loading: files are loaded first and merged, then inline
expsare applied. - Auto-reload: when enabled, changes to any configured file trigger a reload and replace the rules atomically.
- Matching: trailing dots are normalized and matching is case-insensitive.
- Regex rules with invalid patterns are skipped and a warning is logged.
- The plugin logs counts of rules loaded (full, domain, regexp, keyword) after loading.
- Use the plugin's
stats()method to inspect counts programmatically.
- If expected domains are not matching, ensure rules use the intended match type (use
full:for exact matches anddomain:for subdomains). - For large datasets, prefer
domain/fullrules where possible (they are O(1) lookups) and avoid excessive regex rules which are O(n) to evaluate. - If auto-reload isn't picking up changes, verify the process has filesystem read permission and the watched paths are correct.
- Use
default_match_type: domainfor common host-lists so that plainexample.commatches subdomains. - Place more specific domain rules (longer suffixes) before broader ones when relying on domain specificity.
- Keep heavy regex usage to a minimum; prefer targeted patterns.