# VCL import: supported instructions and exact effects This guide describes the VCL **subset implemented by RustProxy 0.39.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 is a human-oriented preview, **not** a lossless backup or a guaranteed re-importable VCL program. 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. ## Where to import, rule order and activation - **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. - A terminal `return(hash)` ends normal `vcl_recv` processing but **does not skip `vcl_hash`**. A terminal `return(pass)` skips lookup and `vcl_hash`. A return/stop does not skip the other, independent response/deliver stages. - Regular cache admission still requires enabled global/vhost caching, an eligible route, method, request policy and response. A `return(hash)` cannot turn on a disabled cache or override `Authorization`/access controls. Supported request header/cookie/query rewrites and backend header edits can still affect an ordinary reverse-proxy response even when cache storage is disabled; deliver-stage edits apply to the final response on HIT, MISS and BYPASS. These rules do not apply to embedded Web Server sources or RustProxy's administration/control-plane responses. ## Supported VCL statements | Hook | Recognized VCL syntax | Actual effect and limits | |---|---|---| | `vcl_recv` | `return(pass);` | Stops request processing for the matching path; bypasses shared cache. | | `vcl_recv` | `return(hash);` or `return(lookup);` | Stops `vcl_recv` and requests a cache lookup. In compatibility mode, may admit a GET/HEAD carrying `Cookie` (with cookie-partitioned variants); other protections remain. | | `vcl_recv` | `unset req.http.Cookie;` | Removes the **whole** request Cookie header, including what is forwarded to the origin. | | `vcl_recv` | `set req.http.X-Device = "mobile";` / `unset req.http.X-Tracking;` | Sets/removes a **safe request header** before later conditions, `vcl_hash`, cache policy and the forwarded origin request. Assignments are constant strings, and a per-vhost edit takes priority over a conflicting global edit. Authentication, identity, request cache policy and transport headers are protected (see below). | | `vcl_recv` | `set req.url = regsuball(req.url, "([?&])(utm_[^=&]*|gclid)=[^&]*", "\1");` | **Restricted conversion only:** recognizes the specific captured-separator, query-parameter-removal pattern. Other `regsub` / `regsuball` rewrites are skipped with warnings; arbitrary URL regex replacement is not supported. | | `vcl_hash` | `hash_data(req.http.X-Name);` | Adds one request header's value to RustProxy's **internal** variant key. It does not automatically add `Vary` for downstream caches. | | `vcl_hash` | `hash_data(req.url);` / `hash_data(req.http.Host);` | Accepted as built-in operations with **no additional rule**: URL/query and normalized Host are already part of the RustProxy key. Other expressions are not imported. `hash_data` in `vcl_recv` is rejected with a warning. | | `vcl_backend_response` / `vcl_fetch` | `set beresp.ttl = 60s;` and `set beresp.grace = 30s;` | Configures cache freshness/grace, within RustProxy limits and policy. Units: `ms`, `s`, `m`, `h`, `d`, `w`, `y` (rounded to whole seconds). Does not automatically rewrite the browser's `Cache-Control`. | | `vcl_backend_response` / `vcl_fetch` | `set beresp.uncacheable = true;` / `= false;` | **RustProxy-specific difference:** `true` disables storing; `false` reverses an earlier **rule-imposed** no-store decision. Varnish itself ignores resetting `beresp.uncacheable` from true to false. In RustProxy, `false` does **not** ignore origin `private`, `no-store`, `Set-Cookie` or other cache admission restrictions. A vhost `false` overrides conflicting global `true`. | | `vcl_backend_response` / `vcl_fetch` | `set beresp.http.X-Name = "literal";` | Replaces the named origin header before cache admission and before delivery. Only a **single quoted constant string** is supported, on an allowed header. | | `vcl_backend_response` / `vcl_fetch` | `unset beresp.http.X-Name;` | Removes the named origin header before cache admission and delivery. | | `vcl_backend_response` / `vcl_fetch` | `unset beresp.http.Set-Cookie;` | A **special dedicated action**, which removes the origin's Set-Cookie before cache policy. Only safe for genuinely public responses. | | `vcl_backend_response` / `vcl_fetch` | `return(pass);`, `return(hit_for_pass);` or `return(uncacheable);` | Marks the response as not storable; **does not** create Varnish hit-for-pass markers. | | `vcl_backend_response` / `vcl_fetch` | `return(deliver);` | Stops the remaining rules in that response hook. | | `vcl_deliver` | `set resp.http.X-Name = "literal";` | Sets/replaces the named header **only on the outgoing response**. Does not change the cache's stored object or variant key. | | `vcl_deliver` | `unset resp.http.X-Name;` | Removes the named header **only from the outgoing response**, including an HIT. | | `vcl_deliver` | `return(deliver);` | Stops further deliver-stage rules on the matching path. | For `set` and `unset` header instructions, HTTP header names are case-insensitive. Quoted strings accept `\"` and `\\` escapes; regex escapes such as `\s` and backreferences such as `\1` are kept literally. **Malformed statements with extra operands are warned about and skipped**, rather than silently treating their prefix as a valid action. Unterminated quoted strings and block comments reject the import. Valid headers and values are checked when a rule is compiled. The importer reports unsupported/invalid statements as warnings (skipped) or parsing errors (import rejected), rather than running them as Varnish code. A rejected header edit no longer discards adjacent valid statements, and long supported action blocks are split at the rule action limit. For repeated header fields, `set` replaces the **entire** field (not one value); `unset` removes **all occurrences** of that field. Assigning `""` creates an empty field, which is not the same as removing it. Neither action merges individual comma-separated `Vary` members. The panel also offers graphical-only actions such as **Set header if missing**, **Ignore backend Cache-Control**, cookie allowlists and explicit query-parameter filtering; do not assume those actions have a one-to-one VCL syntax. ### Request header changes: scope and safeguards ```vcl sub vcl_recv { if (req.url ~ "^/catalog") { unset req.http.X-Tracking; set req.http.X-Device = "mobile"; return(hash); } } sub vcl_hash { hash_data(req.http.X-Device); } ``` Both header edits are visible to later matching rules, the hash calculation and the origin. They also run on cache-disabled reverse-proxy routes (without enabling cache). They **do not** rewrite the client's original `Vary` requirements: if the response varies by `X-Device`, include it in `beresp.http.Vary` or configure it at the origin. A later `unset` is different from setting an empty string. Protected request headers cannot be set or removed by general request rules: `Authorization`, `Cookie` (except the existing dedicated whole-header `unset`), `Cache-Control`, `Pragma`, `Host`, range/precondition headers (`If-*`, `Range`), forwarding and origin identity headers (`Forwarded`, `Via`, `X-Forwarded-*`, `X-Real-IP`, `X-Client-IP`, `CF-Connecting-IP`, `True-Client-IP`), `Proxy-*`, `Sec-*`, `X-RustProxy-*`, `Content-Type`, `Expect` and the protected transport/body header list below. Rejected edits are warned about and never silently applied. Do not assume imported VCL can change authentication or request-cache restrictions. The query-removal conversion accepts only the supported captured-separator `regsuball` pattern. **Every such conversion emits a warning**, because removing parameters with RustProxy's parser can normalize separators differently from a regex replacement. Variable-name classes such as `utm_[a-z]+` are approximated by a prefix wildcard; value patterns ending in `[^&]+` may preserve empty values that `strip_query` removes. **Review generated parameters and warnings** if byte-exact URL behavior matters. Other URL rewrites are deliberately **not** guessed from keywords such as `utm_`. ## Recognized conditions and expressions | 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. | `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. ## `Vary`: before or after the cache? `Vary` is an **allowed** header for both backend (`beresp`) and deliver (`resp`) actions. The phase matters: | VCL statement | Internal cache / stored variants | Response sent to clients and downstream proxies | |---|---|---| | `set beresp.http.Vary = "Accept-Language";` | Replaces the origin's complete `Vary` field before the variant plan is built. Distinct `Accept-Language` requests can have separate stored variants. | Sends the replaced `Vary`, unless later processing or deliver rules modify it. | | `unset beresp.http.Vary;` | Drops origin-specified variant dimensions **before storage**. A response that actually depends on a removed dimension may be reused for the wrong client. | Removes the origin field unless safety handling re-adds `Vary: Cookie`/`Authorization` or later rules set it. | | `set resp.http.Vary = "Accept-Language";` | **No change** to the variant dimensions already computed/stored. | Replaces the final `Vary`; may incorrectly describe the cache key to a CDN. | | `unset resp.http.Vary;` | **No change** to internal variants or HIT behavior. | Removes `Vary` downstream. Dangerous when the response varies by language, encoding, cookies or credentials. | Important details: - `set beresp.http.Vary = "X-Device";` **replaces**, not appends: any previous `Vary: Accept-Encoding` or `Vary: Cookie` is discarded by that assignment. The importer does **not** support expressions such as `beresp.http.Vary + ", X-Device"` or `regsub(beresp.http.Vary, ...)` to merge values. List all required dimensions explicitly in a constant string, or configure them at the origin. - `Vary: *` and malformed `Vary` prevent shared reuse. With a valid `Vary`, RustProxy uses **all retained** dimensions and normalizes selected header families as described in [Cache](CACHE.md#vary-matching-rfc-9111-41). - **Safety exception:** when a request carrying `Cookie` is explicitly allowed by `return(hash)` (or forced caching), RustProxy makes its variant cookie-dependent and can **re-add `Vary: Cookie`** before storage/delivery even if `beresp.http.Vary` removed it. Forced credential variants can likewise add `Vary: Authorization`. This is not a general VCL override of protected request policies. - **Static-file exception:** `Ignore Vary: Cookie for public static assets` may remove just the `Cookie` member from `Vary` only under the documented static extension, explicit `public`, freshness and privacy checks. It does not erase other dimensions. The static-cookie options are separate from manually setting/unsetting `Vary` in VCL. - `vcl_deliver` runs **after** variant selection. Although `unset resp.http.Vary` is accepted, using it on a variant response can make a browser/CDN store an unsafe representation. Do not remove `Vary` only to increase the HIT ratio. Example for a response that **really varies only by language**: ```vcl sub vcl_backend_response { if (bereq.url ~ "^/catalog") { set beresp.http.Vary = "Accept-Language"; set beresp.http.Cache-Control = "public, max-age=60"; unset beresp.http.X-Powered-By; } } ``` This does **not** claim that all catalog responses are safe to share: the application must not vary them by sessions, cookies, compression, permissions or other request headers unless those dimensions are also retained. If compression can change representation bytes, preserve the corresponding `Accept-Encoding` semantics. ## Removing headers, `Cache-Control` and `Set-Cookie` | Example | When removed/changed | Does it affect cache admission? | |---|---|---| | `unset beresp.http.X-Debug;` | On origin response, before storage and client delivery | Only indirectly, e.g. via metadata/policy if applicable | | `unset resp.http.X-Debug;` | On final response (HIT/MISS/BYPASS) | **No** | | `unset beresp.http.Cache-Control;` | Removes origin cache policy before storage | **Yes:** can remove `no-cache`, `private` or `no-store` constraints | | `set beresp.http.Cache-Control = "public, max-age=60";` | Replaces origin policy before storage | **Yes:** origin policy is evaluated as rewritten | | `set resp.http.Cache-Control = "public, max-age=60";` | Changes the client-facing header only | **No:** cannot make a BYPASS into a stored HIT | | `unset beresp.http.Set-Cookie;` | Removes Set-Cookie via special backend rule | **Yes:** removes a reason to reject shared storage | **Security:** rewriting or removing `Cache-Control: private`/`no-store` in `vcl_backend_response`, or stripping `Set-Cookie`, **explicitly discards the origin's protection**. RustProxy's storage policy sees the rewritten response. Only do this for representations proven identical for all users; never for login, account or session-dependent pages. The graphical **Ignore backend Cache-Control** action can likewise override origin privacy directives for RustProxy cache admission even while preserving them in downstream headers; it must be treated as an explicit policy override. Merely enabling Varnish compatibility does *not* strip these directives. `set beresp.ttl` does not by itself erase `private` or `no-store`. The following headers are **protected against general `set`/`unset` actions** in both `beresp.http.*` and `resp.http.*`: `Connection`, `Content-Length`, `Content-Encoding`, `Content-Range`, `Date`, `Keep-Alive`, `Proxy-Authenticate`, `Proxy-Authorization`, `Set-Cookie`, `TE`, `Trailer`, `Transfer-Encoding`, `Upgrade`, `Host`, `Alt-Svc`. An attempted edit is skipped with a warning. The one exception is the **dedicated** `unset beresp.http.Set-Cookie` removal action; arbitrary `set beresp.http.Set-Cookie` and `unset resp.http.Set-Cookie` are not supported. Other proxy subsystems may also generate or normalize response headers after backend rules have run. Example for final-response-only cleanup (does not affect cache identity, TTL or origin storage): ```vcl sub vcl_deliver { unset resp.http.X-Debug; set resp.http.X-Policy-Name = "catalog-public"; return(deliver); } ``` ## Cookies and `return(hash)` In compatibility mode (`cache.varnish_compatible=true`), `return(hash)` can opt in to caching eligible GET/HEAD requests with Cookie. **It does not remove the Cookie header.** Remaining cookie values partition the RustProxy variant, and the response includes a Cookie `Vary` dimension for downstream caches. This is safer than sharing all cookie-bearing requests, but reduces HIT rates. Explicit `return(pass)` should intercept session cookies **before** `return(hash)`: ```vcl sub vcl_recv { if (req.http.Cookie ~ "(^|; *)session=") { return(pass); } if (req.url ~ "^/catalog") { return(hash); } return(pass); } ``` Use `unset req.http.Cookie;` only when the origin does not need **any** cookies for that route. A graphical **Strip cookies** action can keep an allowlist (not imported from arbitrary VCL cookie rewriting). In strict RFC mode (`cache.varnish_compatible=false`), `return(hash)` does not bypass the request Cookie restriction. `Authorization`, non-GET/HEAD traffic, request `no-store`, access/authentication and sticky-session checks still apply. ## `no-cache` and TTL - `varnish_compatible=true` and positive `cache.default_ttl_seconds` (or an explicit positive `set beresp.ttl`) may treat an otherwise eligible origin `Cache-Control: no-cache` as fresh for that TTL, **without requiring `public`**. This is RustProxy's configured override, **not** vanilla Varnish's built-in behavior. - `varnish_compatible=false` honors `no-cache` revalidation, including when a TTL action is present. An explicit *backend header rewrite* removing `no-cache` changes the response policy in both modes; that is a different and potentially unsafe operation. - Backend `private`, `no-store`, `Set-Cookie`, malformed `Vary`, unsupported status, invalid headers and size bounds still block storage **unless an administrator explicitly rewrites the affected cache-policy headers via trusted rules**. Client/request restrictions remain separate. - **Only HTTP 200 origin responses are storable in RustProxy 0.39.0.** Setting `beresp.ttl` for `404`, `301` or `302` does not create a negative/redirect cache. The misleading 404 TTL template was removed from the graphical editor. Deliver-stage header rules can still edit those responses without making them cacheable. - Hit-for-miss / hit-for-pass and `beresp.keep` are intentionally not imported. RustProxy already coalesces eligible misses and briefly remembers uncacheable fills for its collapse strategy, and independently retains validators for conditional revalidation. These are **not** Varnish-compatible hit-for-miss/pass objects or programmable `keep` semantics. ## Test an imported rule set 1. Import VCL in the appropriate global or per-vhost Rules editor. With warnings the importer **does not add the converted rules automatically**. Read each warning; either revise the VCL and rerun or explicitly click **Add partial import (reviewed)**. No VCL is executed directly at runtime. The resulting rules are still unsaved until you save the settings. Closing the importer or modifying its source invalidates any outstanding parse result; an older API response cannot add rules after cancellation. Do not treat **Copy as VCL** as a backup/round trip; use RustProxy configuration exports for exact rules. 2. Expand **Test a request** (two compact sections: HTTP request and backend response) in the global, ordinary-vhost or Docker-vhost Rules editor. Supply URL or path, method, Cookie/other request headers, client IP, example backend status and headers (`Cache-Control`, `Vary`, `Set-Cookie`); inspect matched/suppressed rules, backend header edits, cacheability, TTL/grace and deliver actions. The global tester previews unsaved global rules with the selected vhost's saved rules; a local tester previews unsaved vhost rules with saved applicable global rules, unless **Ignore global cache rules** is enabled. For a path-only test the current local hostname is sent as `Host` if no explicit Host header was provided; full URLs and explicit Host headers win. The tester does **not** simulate other unsaved cache settings and does **not** send a request to the backend. A not-yet-saved vhost may lack its saved settings in the preview. Use real HTTP requests for final HIT/MISS verification. 3. Save the rules, then send the same `GET` twice (and change one `Vary` dimension) against a real reverse-proxy vhost. Inspect `X-Cache` / `X-Cache-Reason` or `Server-Timing`, depending on enabled diagnostics, plus the **actual delivered headers**. A response can be a MISS yet remain ineligible for storage. 4. Test session cookies, `Authorization`, privacy directives, compressed variants, HIT versus BYPASS and global versus per-vhost conflicts before production. If the origin's behavior differs by a header, verify the correct `Vary` is present in both the internal storage decision and the downstream response. See [HTTP cache](CACHE.md), [Cache API](API.md), and [Security](SECURITY.md) for cache settings and operational limits.