This commit is contained in:
Mateusz Gruszczyński committed 2026-11-25 15:47:34 +01:00
1 parent 6df256cdbb
commit 0d6249e383
159 files changed
+16737 -1971

No files matched your search

+58 -3
View File
@@ -1,6 +1,6 @@
# VCL import: supported instructions and exact effects
This guide describes the VCL **subset implemented by RustProxy 0.39.2**, not the full Varnish Configuration Language. It is based on the VCL importer and cache-rule engine. Importing VCL **converts statements into graphical cache rules (which must then be saved)**; RustProxy does not execute arbitrary VCL text at request time. Unsupported instructions may be skipped with warnings or cause a parse error; they are not executed as Varnish code. **In the graphical importer, warnings pause conversion:** no rules are added until you explicitly choose **Add partial import (reviewed)**. Even after adding, you must separately save the configuration. The read-only VCL export is a human-oriented preview, **not** a lossless backup or a guaranteed re-importable VCL program.
This guide describes the VCL **subset implemented by RustProxy 0.42.0**, not the full Varnish Configuration Language. It is based on the VCL importer and cache-rule engine. Importing VCL **converts statements into graphical cache rules (which must then be saved)**; RustProxy does not execute arbitrary VCL text at request time. Unsupported instructions may be skipped with warnings or cause a parse error; they are not executed as Varnish code. **In the graphical importer, warnings pause conversion:** no rules are added until you explicitly choose **Add partial import (reviewed)**. Even after adding, you must separately save the configuration. The read-only VCL export for ordinary flat rules is a human-oriented preview, **not** a lossless backup or a guaranteed re-importable VCL program. Structured VCL imports use a JSON preview/export that preserves their control flow.
For a short operational reference inside the panel, open **Cache & VCL guide** from **Settings → Cache**, the ordinary **Vhost → Cache** editor or **Docker vhosts → Cache**. The same modal works in all three places; example VCL is pasted into the importer of the editor that opened the guide, and the modal labels that scope. The modal shows the current compatibility-mode, fallback-TTL and grace settings, explains `Vary` and header mutations with examples, and identifies unsupported Varnish hooks. It complements this exact syntax reference; it does not execute VCL or save settings.
@@ -8,6 +8,16 @@ For the **complete reference to all 42 quick-rule templates** (conditions, stage
## Where to import, rule order and activation
Since 0.42.0, optional [HTTP policy rules](POLICY.md) can cooperate with these
rules. Policy request edits run before `vcl_recv`/`vcl_hash`, policy backend
response edits run after existing `beresp` edits but before cache planning,
policy delivery runs after `vcl_deliver`, and `after_response` runs after
compression and legacy dynamic headers. Existing VCL order, local-over-global
priority and terminal return semantics are unchanged. Either engine's explicit
pass wins over lookup; existing VCL TTL/grace assignments take precedence over
policy assignments. New policy Global → Vhost → Location ordering does not
replace the VCL ordering described below.
- **Settings -> Cache -> Rules**: global cache rules, optionally targeted to particular vhosts.
- **Vhosts -> Cache -> Cache rules for this vhost**: rules for one vhost (ordinary or Docker-generated). **Ignore global cache rules** disables the global rules for that vhost.
- Imported rules and graphical rules use the same engine. Within each stage, **vhost rules run first**, followed by applicable global rules. A vhost edit to the same header or supported scalar setting wins over a conflicting global edit. In one scope, later matching edits win unless `stop`/`return(...)` terminates the stage.
@@ -63,17 +73,62 @@ The query-removal conversion accepts only the supported captured-separator `regs
## Recognized conditions and expressions
The corrected 0.42.0 importer records explicit branch selection. Each
`if`/`elsif`/`else` chain chooses its branch once when execution reaches it.
Changing or unsetting a condition's header inside that branch does not enter
its `else` or skip the remaining nested/tail statements. A later, independent
condition still reads the current, possibly modified headers. The same rule
applies in request, hash, backend-response and delivery hooks.
**Upgrade existing imports:** saved flat rules from an older importer retain
their existing behavior. Their JSON no longer contains enough information to
recover the original branch boundaries. Re-import the original VCL with 0.42.0,
review the draft tester, replace the old converted rules and save. Do not append
the new import while leaving the old actions enabled. Native graphical rules
do not require conversion.
| Form | Example | Notes |
|---|---|---|
| URL, method, request headers | `req.url ~ "^/assets/"`, `req.method == "GET"`, `req.http.Cookie` | `req.url` includes path and query; an unqualified request header tests presence. `bereq.url` and `bereq.http.X` are accepted as rule-request aliases. |
| Backend/delivery status and headers | `beresp.status == 200`, `beresp.http.Content-Type ~ "^text/"`, `resp.http.X-Flag` | Evaluated against the response at the relevant stage; earlier supported header mutations are visible to subsequent conditions. |
| Comparisons | `==`, `!=`, `~`, `!~` | Equality and regex matching for supported request/response variables. |
| Status comparisons | `beresp.status >= 500`, `resp.status < 400` | Also accepts `>`, `<=`, `==`, `!=`. |
| Branching | `if`, `elsif`, `else`, nested blocks, `&&`, `||`, `!`, parentheses | Branch guards are preserved in the generated rules, subject to the rule/condition limits. |
| Branching | `if`, `elsif`, `else`, nested blocks, `&&`, `||`, `!`, parentheses | The selected branch is retained in the generated control-flow group; independent later conditions observe earlier edits. Subject to rule/condition limits. |
`client.ip` with a Varnish ACL is **not imported**; the graphical rules have a client IP/CIDR condition instead. `include`, external modules, backend/ACL/probe definitions and custom subroutines are not loaded as executable configuration. Arbitrary functions, variables, string concatenation, dynamic header expressions, `pipe`, `restart`, `purge`, `synth` and hit-for-miss/hit-for-pass behavior are **not** implemented. Import is a conversion, not a promise of runtime Varnish equivalence.
Limits include a maximum VCL source of 256 KiB; the compiled cache-rule lists are limited to 128 rules, 16 conditions and 16 actions per rule. A complex boolean expression may expand to too many rules and be skipped with a warning. Use the graphical tester to verify the imported behavior.
Limits include 256 KiB of VCL source, 128 canonical rules per list (including
branch-entry markers), and 16 actions per rule. A branch has up to 128 OR
alternatives with 16 conditions each; an `if` chain has at most 16 branches.
A group permits 16 enclosing branch guards and 2,048 condition nodes in total.
The parser also limits nested blocks and unary/grouped expressions to depth 64.
Unsupported or excessive branches are skipped with warnings or rejected at
parsing/validation; review partial imports and use the graphical tester before
saving.
### Saved control flow and editor operations
Fresh imports carry optional `vcl_flow` metadata on their canonical cache rules.
The importer generates a versioned group ID, a zero-based `index`, the total
`count`, and references to earlier branch selections in `guards`. A branch-entry
rule has no actions; its `branches[].any` contains OR alternatives, each an AND
list of ordinary rule conditions. A final `[[]]` predicate represents `else`.
Action rules use the selected branch without re-evaluating its original guard.
Selection is private to the request, hook and configured scope, including when
the same import is used locally and globally.
Keep the complete import together. The panel moves, copies, enables, disables,
removes and assigns Vhosts to the whole group. Copies receive fresh group IDs.
Branch structure is read-only in the graphical editor; edit the original VCL
and replace its import to change that structure. The JSON preview/export keeps
the metadata, whereas the ordinary flat-rule VCL preview cannot represent it.
Configuration validation rejects incomplete or reordered groups, cross-hook
references, mixed enable/scope states and invalid branch ancestry before
activation. Rules without `vcl_flow` retain independent sequential evaluation.
New control-flow configurations require 0.42.0 or newer. For rollback, restore
the pre-upgrade configuration; deleting metadata would make guarded actions
unconditional. Keep the original VCL source alongside a full JSON backup.
## `Vary`: before or after the cache?