v0.39.0
This commit is contained in:
1 parent
5e43752041
commit
15425fb803
34 files changed
+1423
-89
No files matched your search
+1
-1
@@ -37,7 +37,7 @@ The current bundled `src/admin/openapi.json` declares these operations (among ot
|
||||
|
||||
Some paths have additional DELETE/PATCH operations, job-status resources, query parameters or restricted actions. Use OpenAPI for the **actual fields/methods**, not guesses based on a table. `GET /metrics` here is not a replacement for the separate Prometheus exporter.
|
||||
|
||||
For browser polling, `GET /api/cache?view=live`, `GET /api/transform?view=live` and `GET /api/traffic?view=live` omit static response members that do not need to be retransmitted on every interval. Their `revision` identifies the active configuration; when it changes, clients should fetch the corresponding endpoint without `view=live` and refresh their cached static fields. Requests without `view=live` remain the complete compatibility form. Cache live responses contain metrics/dashboard/bans, Transform live responses contain resources/metrics, and Traffic live responses retain current settings/GeoIP/analytics while omitting the static Vhost list. Unknown `view` values are rejected.
|
||||
For browser polling, `GET /api/cache?view=live`, `GET /api/transform?view=live` and `GET /api/traffic?view=live` omit static response members that do not need to be retransmitted on every interval. Their `revision` identifies the active configuration; Cache and Traffic additionally return `catalog_version` (a fingerprint of the effective Vhost list, including Docker publications). If either revision or this fingerprint changes, clients should fetch the corresponding endpoint without `view=live` and refresh their cached static fields. Requests without `view=live` remain the complete compatibility form. Cache live responses contain metrics/dashboard/bans, Transform live responses contain resources/metrics, and Traffic live responses retain current settings/GeoIP/analytics while omitting the static Vhost list. Full Cache and Traffic responses provide readable `vhosts[].label` and `vhosts[].docker` together with the stable `id`; Docker-generated IDs are valid cache purge/invalidation and analytics scopes. Unknown `view` values are rejected.
|
||||
|
||||
Certificate inspection accepts `{ "cert_file": "filename.pem" }` for a managed file or an absolute external path and returns `{ "cert_file": "...", "covered_hosts": ["example.com"] }`. It applies the existing certificate-file trust and size checks and reads no private key. It makes no configuration or permission changes. This POST requires the signed-in administrator's normal Origin, request-marker and CSRF checks; general RO/RW API tokens and certificate-only credentials cannot call it.
|
||||
|
||||
|
||||
+7
-1
@@ -9,6 +9,12 @@ The **Static & diagnostics** subtab provides **Ignore request cookies for static
|
||||
|
||||
**Safety requirement:** use both options only when the complete static response (body **and headers**) is identical for all visitors regardless of Cookie. `Vary: Cookie` is a declaration that content may vary, so overriding it on a genuinely session-dependent file can expose one user's cached variant to another. RustProxy applies this override only to responses with an explicit `Cache-Control: public` directive, positive remaining freshness (without mandatory revalidation) and no `Set-Cookie`, `private`, `no-store` or invalid Vary. A zero-TTL response, including `public` with no configured fallback TTL, retains `Vary: Cookie` even if it can be stored for later revalidation. If the response is not cacheable, `Vary: Cookie` is passed through unchanged. Do not enable this optimization for user-specific downloads, generated PDFs, account JSON, or any path where Flask or another origin changes content according to a session cookie; prefer removing the needless `Vary: Cookie` at the origin where possible.
|
||||
|
||||
### CDN security cookies (opt-in VCL template)
|
||||
|
||||
The cache rules template menu now includes **CDN technical cookies** for Cloudflare (`__cf_bm`, `cf_clearance`, `_cfuvid`, `__cfruid`, `__cfseq`) and Akamai (`_abck`, `ak_bmsc`, `bm_sz`, `bm_sv`). It bypasses non-GET/HEAD methods, restricted application paths and `Authorization`. It strips the entire Cookie header **only if all Cookie fields contain allowlisted technical cookies**, and bypasses any request with a remaining Cookie (for example `session`, `wordpress_logged_in_*`, CSRF tokens or other personalized cookies). The source equivalent is [`examples/vcl/cdn-technical-cookies.vcl`](../examples/vcl/cdn-technical-cookies.vcl). Import it only after reviewing warnings; enable the graphical template only on tested public Vhosts. Some challenge cookies (especially `cf_clearance`, `_abck` and `ak_bmsc`) are important to specific origin/CDN configurations; removing them can break a challenge flow. **This is not turned on automatically for existing Vhosts.**
|
||||
|
||||
**Do not extend** `Ignore Vary: Cookie for public static assets` to a general "Ignore Vary" control. `Accept-Encoding`, `Accept-Language`, `Accept`, `Origin`, `User-Agent` and custom response-specific dimensions can change bytes, permissions or CORS headers. Keep the response's actual dimensions and use the existing safe normalization of recognized list fields below, or remove an unnecessary `Vary` at the origin only after proving the response is invariant. A VCL `unset beresp.http.Vary` is *possible*, but it is not the equivalent of a guarded static-file optimization.
|
||||
|
||||
## `Vary` matching (RFC 9111 §4.1)
|
||||
|
||||
Cached variants use the response's `Vary` field names together with the original request's nominated fields. Reuse requires a match in **every** retained `Vary` dimension; `Vary: *` is never reusable. An absent request field is not equivalent to a present but empty field.
|
||||
@@ -60,7 +66,7 @@ Imported VCL is compiled into the **same rule engine** as the global and per-Vho
|
||||
|
||||
### Complete VCL support and `Vary`/header overrides
|
||||
|
||||
See [VCL compatibility and header overrides](VCL.md) for a statement-by-statement compatibility matrix, global/per-Vhost priority, stage timing, exact `set`/`unset` support, `Vary` behavior and protected headers. **`beresp.http.Vary` affects cache variants; `resp.http.Vary` only affects the outgoing header.** Unsetting either can break downstream cache correctness. `set/unset beresp.http.Cache-Control` changes cache admission policy, while deliver-stage header edits do not. A deliberately rewritten `private`/`no-store` header or removed `Set-Cookie` no longer protects the representation, so use these actions only for public content.
|
||||
See the [practical VCL traffic cookbook](VCL_TRAFFIC_COOKBOOK.md) for examples, expected request outcomes and curl tests; [VCL compatibility and header overrides](VCL.md) and the [exhaustive support matrix](VCL_SUPPORT_MATRIX.md) for a statement-by-statement compatibility matrix, global/per-Vhost priority, stage timing, exact `set`/`unset` support, `Vary` behavior and protected headers. **`beresp.http.Vary` affects cache variants; `resp.http.Vary` only affects the outgoing header.** Unsetting either can break downstream cache correctness. `set/unset beresp.http.Cache-Control` changes cache admission policy, while deliver-stage header edits do not. A deliberately rewritten `private`/`no-store` header or removed `Set-Cookie` no longer protects the representation, so use these actions only for public content.
|
||||
|
||||
### Explicit Cookie lookup with imported VCL
|
||||
|
||||
|
||||
@@ -177,6 +177,19 @@ For each published Docker Vhost, **Live logs** appears directly beside **Open ap
|
||||
|
||||
These are **HTTP requests processed by RustProxy**, not the application's Docker container stdout/stderr. The viewer uses RustProxy's bounded in-memory live request history; requests appear when completed, not as a container terminal stream. Stored Docker stdout/stderr are not retrieved from the agent. The dialog is administrator-only, and no Docker log-reading endpoint is exposed.
|
||||
|
||||
### Cache and Traffic scopes for generated Docker Vhosts
|
||||
|
||||
The **Cache** and **Traffic** pages list **all effectively compiled reverse-proxy vhosts**, including active Docker publications; they do not limit the selector to Vhosts saved in the ordinary-Vhosts configuration. Selectors display **container name — hostname (Docker: agent name)** when observed, and retain the stable generated Vhost ID as the underlying API value and tooltip. A temporarily missing container falls back to its saved hostname; it is not shown as an opaque Docker hash in the normal selector. Cache scope counters, per-service effective cache settings, object lists, purge and invalidation use the same generated ID. The full API responses include `vhosts[].label`, `vhosts[].docker` and `catalog_version`; the last changes when Docker publication inventory changes even if the persisted configuration `revision` does not. Polling clients use `catalog_version` to reload the full scope list. If a label-only publication disappears while selected, the Cache/Traffic panel resets the invalid scope to **All Vhosts** instead of repeatedly polling a now-unknown ID.
|
||||
|
||||
### If a Docker container temporarily disappears
|
||||
|
||||
- **Manually published service**: its assignment (`service_key`, hostname, cache/VCL rules, security options, certificate/listener selection and other per-app settings) is stored in RustProxy configuration; the absence of a Docker inventory entry **does not delete it**. A newly compiled generated Vhost can have no usable backend and return **503** during the gap. Once the same service key and network binding reappear and the agent reports them, the assignment is used again automatically.
|
||||
- **Publish-from-labels only**: the generated publication is derived from the *current* agent inventory and container labels; when the service disappears from a successful inventory it is absent from the effective configuration. It will be generated again if the service reappears with a matching, valid label configuration and no hostname conflict. There is no saved per-service manual state unless **Apply changes** was used (which converts it to a persisted manual assignment).
|
||||
- **Agent temporarily unreachable**: the Docker polling layer can retain its last successful inventory; a failed poll is not proof that a container disappeared. Do not use missing status alone to delete an assignment.
|
||||
- **Identity changes**: changing a Compose/service name, key, or selected publication labels can yield a *different* service key, so automatic recovery of a manually saved mapping is not guaranteed until you select the correct service again. Stable service names and persistent manual assignments are preferable when keeping settings matters.
|
||||
|
||||
These guarantees concern **configuration**, not persistence of in-memory Traffic history, cache HIT counters or old cached objects across unrelated process restarts. Back up RustProxy's persistent configuration separately.
|
||||
|
||||
### Per-vhost traffic statistics
|
||||
|
||||
Every published vhost on an enabled Docker agent has a **Traffic statistics** disclosure directly below **Configure vhost**. It starts collapsed, uses the same six status/requests/active/errors/latency/traffic-per-second tiles and **Lifetime request rate** chart as an ordinary Vhost, and can be opened individually. The **Expand all statistics / Collapse all statistics** toolbar button toggles every published Docker vhost at once (including rows hidden by search or the local Hide action). The chosen disclosure state survives live list refreshes during the current panel session; it resets on sign-out.
|
||||
|
||||
+3
-1
@@ -66,13 +66,14 @@ RustProxy is a single service that combines a reverse proxy, a static/PHP web se
|
||||
- Shared HTTP cache with a memory tier (HOT) and an optional disk tier (COLD).
|
||||
- RFC 9111 freshness, validators and `Vary` with conservative header-aware normalization (known comma-list fields, language/encoding/charset qualities and media types), while preserving opaque values and quoted strings; stale-while-revalidate, stale-if-error and request coalescing. Configurable static-extension exception for cookie-independent assets: omit `Vary: Cookie` only for explicitly public cacheable responses, preserving all other Vary dimensions.
|
||||
- Varnish-compatible policy option, forced caching rules and per-location cache switches.
|
||||
- Graphical [cache rules](CACHE.md#cache-rules-vcl-style) with global and per-Vhost precedence, terminal VCL pass/hash behavior, ordered safe request-header/cookie/query rewrites, vcl_hash variants, reversible rule-only no-store decisions, backend-response header edits before cache policy, and delivery header overrides; includes a shared, responsive two-section tester in global, ordinary vhost and Docker vhost editors, a scope-aware in-panel VCL guide, and a warning-reporting VCL subset importer. The exact VCL syntax, backend vs deliver `Vary`/header mutations and safety restrictions are listed in [VCL compatibility](VCL.md).
|
||||
- Graphical [cache rules](CACHE.md#cache-rules-vcl-style) with global and per-Vhost precedence, terminal VCL pass/hash behavior, ordered safe request-header/cookie/query rewrites, vcl_hash variants, reversible rule-only no-store decisions, backend-response header edits before cache policy, and delivery header overrides; includes a shared, responsive two-section tester in global, ordinary vhost and Docker vhost editors, a scope-aware in-panel VCL guide, and a warning-reporting VCL subset importer. The exact VCL syntax, backend vs deliver `Vary`/header mutations and safety restrictions are listed in [VCL compatibility](VCL.md); the [traffic cookbook](VCL_TRAFFIC_COOKBOOK.md) includes ready-to-import examples and expected live request outcomes.
|
||||
- RFC 9211 `Cache-Status` and optional `X-Cache` diagnostics.
|
||||
- Purge and ban from the panel, the API or HTTP PURGE/BAN from allowlisted addresses.
|
||||
- Live compression with gzip, Brotli, Zstandard and deflate.
|
||||
- Optional minification of JavaScript, CSS, HTML, SVG and JSON with memory budgets.
|
||||
|
||||

|
||||
- CDN security-cookie template (Cloudflare and Akamai) that strips whole Cookie headers only when every cookie is allowlisted, with session/Authorization/path bypass; opt-in for verified public content. The [VCL support matrix](VCL_SUPPORT_MATRIX.md) documents supported and deliberately excluded constructs.
|
||||
- **VCL subset only:** graphical rules are the canonical configuration. Partial imports require review; the VCL text shown in the editor is an approximate preview. Cache storage is restricted to HTTP 200 (non-200 responses can still receive deliver-header rules). See [VCL import](VCL.md).
|
||||
|
||||
## Monitoring and logs
|
||||
@@ -84,6 +85,7 @@ RustProxy is a single service that combines a reverse proxy, a static/PHP web se
|
||||
- Live request log in the browser and in the terminal (`--livelogs`).
|
||||
- Stored JSON access logs with search syntax, per-Vhost log files and an error log.
|
||||
- Prometheus exporter with token/CIDR protection, JSON metrics and a compact summary endpoint.
|
||||
- Cache and Traffic scope selectors include Docker-generated Vhosts with readable container/domain/agent labels and a Docker-inventory fingerprint, even when the saved configuration revision is unchanged.
|
||||
- Lightweight revision-aware polling views for Cache, Traffic and Transform keep the administration panel responsive without repeatedly transferring static configuration.
|
||||
- Grafana dashboard and Nagios checks included.
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ Guides for operating RustProxy: installation, publishing services, security, cer
|
||||
## Performance and delivery
|
||||
|
||||
- [Cache](CACHE.md) — scope-aware Cache & VCL help modal from global/Vhost/Docker editors, a compact rule tester, HOT/COLD cache, RFC 9111 `Vary` matching/normalization, safe static-asset cookie exceptions, freshness, `Cache-Status` and invalidation.
|
||||
- [VCL traffic cookbook](VCL_TRAFFIC_COOKBOOK.md) — 11 ready-to-import examples, public/private HTTP traffic cases, Cookie/`Vary` variants, `curl` verification and failure modes.
|
||||
- [Complete VCL support matrix](VCL_SUPPORT_MATRIX.md) — line-by-line supported, restricted, graphical-only, intentionally excluded and missing instructions, with test scenarios.
|
||||
- [VCL compatibility and header overrides](VCL.md) — supported VCL import syntax, safe request-header edits, `beresp.uncacheable` precedence, `Vary`, cookies, approval of partial imports and storage limits.
|
||||
- [Response delivery](RESPONSE_DELIVERY.md) — compression, transformations and response headers.
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ This guide describes the VCL **subset implemented by RustProxy 0.39.0**, not the
|
||||
|
||||
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.
|
||||
|
||||
For an expanded **implemented / restricted / graphical-only / intentionally excluded / not implemented** inventory, consult the [complete VCL support matrix](VCL_SUPPORT_MATRIX.md). For practical production scenarios, **11 copyable VCL examples**, HTTP traffic outcomes, a `curl` validation plan and troubleshooting, use the [VCL traffic cookbook](VCL_TRAFFIC_COOKBOOK.md) (also available from the embedded Reader). It names each supported hook, variable and return action and the deliberate HTTP/security boundaries.
|
||||
|
||||
## Where to import, rule order and activation
|
||||
|
||||
- **Settings -> Cache -> Rules**: global cache rules, optionally targeted to particular vhosts.
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
# VCL capability matrix: implemented, limited and unsupported
|
||||
|
||||
**Applies to the RustProxy 0.39.0 source tree with the Docker/Cache/Traffic and CDN-template fixes.** This is an implementation inventory, not a statement of general Varnish compatibility. The authoritative implementation is `src/cache/vcl.rs` (tokenization and import), `src/cache/rules.rs` (validation and rule evaluation), and `src/cache/policy.rs` / `src/cache/lookup.rs` (shared-cache admission and lookup). See [VCL syntax and header semantics](VCL.md) for implementation details, the [VCL traffic cookbook](VCL_TRAFFIC_COOKBOOK.md) for ready-to-import VCL and a request/response scenario matrix, and [HTTP cache](CACHE.md) for cache policy.
|
||||
|
||||
## Practical examples and traffic scenarios
|
||||
|
||||
The companion [VCL traffic cookbook](VCL_TRAFFIC_COOKBOOK.md) contains **11 complete VCL examples** (including an intentionally restricted importer example and a high-risk advanced example), an HTTP request/response behavior matrix, `curl` checks, expected `PASS`/`MISS`/`HIT` behavior and troubleshooting. The standalone source files are in [`examples/vcl/`](../examples/vcl/). They cover public catalogs, JSON APIs, private routes, CDN cookies, public static files, multilingual responses, A/B variants, SSE/webhooks/errors, safe header changes, query normalization and highly restricted Set-Cookie removal. Each example states its origin/privacy contract and importer limitations.
|
||||
|
||||
| Goal | Available through imported VCL | Native GUI/API required or not supported |
|
||||
|---|---|---|
|
||||
| Bypass admin/session/credentialed requests | `vcl_recv` with `return(pass)` | Authentication and access policy remain native |
|
||||
| Cache public GET JSON/catalog | `return(hash)` plus conditional `beresp.ttl` | Global/Vhost cache must already be enabled; only 200 can be stored |
|
||||
| Strip CDN technical cookies | Entire Cookie header removal after an exact allowlist | Removing one cookie by name from a mixed header: graphical action only |
|
||||
| Safely ignore `Vary: Cookie` on public static | VCL can remove request Cookie, but **not** safely override `Vary` | Narrow native static-asset settings, not a general Ignore Vary feature |
|
||||
| Multilingual/CORS/encoded responses | Preserve origin `Vary`; optional internal `vcl_hash` dimension | Origin must emit the complete downstream `Vary` dimensions |
|
||||
| Webhooks, SSE, transient errors | PASS, `beresp.uncacheable=true` | Retries, stale-if-error, streaming and backend failures are native behaviors |
|
||||
| Query tracking normalization | Recognized `regsuball` pattern, **with warning** | Prefer graphical Strip query params; arbitrary regex rewriting unsupported |
|
||||
| Negative cache, full VMOD, `vcl_hit`/`vcl_purge` | **No** | Not implemented as VCL in this release |
|
||||
|
||||
## Read this before deploying VCL
|
||||
|
||||
1. RustProxy **does not run a VCL interpreter**. `POST /api/cache/rules/import-vcl` parses a limited source document and returns **graphical rules plus warnings**. A rule runs only after it is accepted and the configuration is saved.
|
||||
2. A syntactically accepted VCL instruction can have **different runtime behavior** from Varnish. In particular, `return(hash)` does not disable RustProxy's authorization and privacy safeguards, and `return(hit_for_pass)` does not create a hit-for-pass object.
|
||||
3. **Warnings are significant.** The editor will not add a partial import automatically; choose **Add partial import (reviewed)** only if you have checked every skipped instruction and the resulting graph. An import that fails with a parser error creates no rule set.
|
||||
4. VCL support is **limited to reverse-proxy HTTP Vhosts**. It does not provide Varnish behavior for the built-in static Web Server, PHP or the administration API. The same rule editor is available for manually configured and Docker-generated reverse-proxy Vhosts.
|
||||
5. Cache rules do not enable caching by themselves. Both global and effective per-Vhost cache policy must permit it. Request rewrites can still be relevant on a cache-disabled reverse-proxy route.
|
||||
|
||||
## Status terminology
|
||||
|
||||
| Status | Exact interpretation |
|
||||
|---|---|
|
||||
| **Supported** | Converted into a validated RustProxy cache rule; the documented effect is implemented. |
|
||||
| **Restricted** | Converted only for the listed syntax, stage or constant form; alternatives warn and are skipped. |
|
||||
| **Graphical only** | RustProxy has an equivalent or related rule editor action, but VCL source does **not** import it exactly. |
|
||||
| **Unsupported (intentional boundary)** | Not part of the importer/runtime by design of a graph-based, safety-constrained proxy, or intentionally not implemented as Varnish semantics. Do not assume it will be added. |
|
||||
| **Not implemented** | No corresponding VCL conversion/runtime functionality exists in this version; roadmap and future support are unspecified. |
|
||||
|
||||
## 1. Hooks and program structure
|
||||
|
||||
| Varnish construct | Status | What RustProxy actually does |
|
||||
|---|---|---|
|
||||
| `sub vcl_recv { ... }` | Supported subset | Request-stage rules, in statement order; may bypass cache, request lookup, strip cookies or perform safe rewrites. |
|
||||
| `sub vcl_hash { ... }` | Restricted | Becomes a separate request hash stage. Runs after `vcl_recv` with a hash/lookup decision, but not after `return(pass)`. |
|
||||
| `sub vcl_backend_response { ... }` | Supported subset | Response-stage changes run against the origin response before shared-cache admission. |
|
||||
| `sub vcl_fetch { ... }` | Supported alias | Maps to response-stage behavior, not a historical Varnish backend state machine. |
|
||||
| `sub vcl_deliver { ... }` | Supported subset | Changes outgoing response headers. Does not alter stored variants/TTL. |
|
||||
| Other hooks: `vcl_init`, `vcl_fini`, `vcl_hit`, `vcl_miss`, `vcl_pass`, `vcl_pipe`, `vcl_synth`, `vcl_backend_fetch`, `vcl_backend_error`, `vcl_purge` | Not implemented | Unrecognized subroutine names generate an import warning; their body is not executed. |
|
||||
| `sub my_helper { ... }` and `call my_helper;` | Unsupported (intentional boundary) | No custom executable subroutines, VCL callbacks or extension language. |
|
||||
| Top-level `vcl`, `import`, `include` directives | Restricted | Lexer accepts them and skips to the terminating semicolon. **It does not load a module or another file.** |
|
||||
| Top-level `backend`, `acl`, `probe` definitions | Restricted | Blocks are skipped with warnings. Use RustProxy backend, health-check and ACL configuration. |
|
||||
| Arbitrary top-level statements | Not implemented | The importer reports an error instead of executing unknown declarations. |
|
||||
| `#`, `//`, `/* ... */` comments | Supported | Comments discarded; unclosed block comment is a parsing error. |
|
||||
| Short `"..."` and VCL long `{ " ... " }` string forms | Restricted | String tokenization is supported. Only specific instructions accept a string value; long strings do not make arbitrary VCL code executable. |
|
||||
|
||||
## 2. Branches, variables and comparisons
|
||||
|
||||
| Syntax or variable | Status | Rules and caveats |
|
||||
|---|---|---|
|
||||
| `if (...) { ... }`, `elsif (...)`, `else`, nested `if` | Supported | Branch guards and previous-branch exclusions are converted; not a runtime scripting language. |
|
||||
| `&&`, `||`, `!`, parentheses | Supported with limits | Conditions expand to sets of graphical rule guards. Very complex expressions may exceed rule limits and are skipped with warnings. |
|
||||
| `req.url`, `bereq.url` | Supported for comparisons | Match path **and query** together. These aliases do not permit arbitrary URL rewrite. |
|
||||
| `req.method`, `req.request`, `bereq.method` | Supported | Comparisons to constant values. |
|
||||
| `req.http.<Header>`, `bereq.http.<Header>` | Supported | Header existence, equality and regex comparison; `req.http.Host` is mapped to normalized host scope. |
|
||||
| `beresp.status`, `resp.status`, `obj.status` | Supported in response/deliver | Numeric code comparisons: `==`, `!=`, `<`, `<=`, `>`, `>=`. They compile to one status or a bounded range. |
|
||||
| `beresp.http.<Header>`, `resp.http.<Header>`, `obj.http.<Header>` | Supported in response/deliver | Response-header existence, equality and regex matching. Content-Type has a dedicated canonicalized condition. |
|
||||
| `==`, `!=`, `~`, `!~` | Supported | For appropriate recognized request/response fields; regex is Rust regex matching rather than arbitrary Varnish/PCRE execution. |
|
||||
| `client.ip ~ my_acl` | Not implemented for VCL | The importer warns. The **graphical** editor can match client IP/CIDR (see below). |
|
||||
| `std.*`, `server.*`, `req.backend_hint`, `req.url.path`, `req.url.qs`, `bereq.retries`, `beresp.backend.*`, `obj.hits`, `now`, TLS-specific VCL vars and VMOD variables | Not implemented | Unsupported variable/condition warning; they are not silently assigned live values. |
|
||||
| Arithmetic, regex capture substitution in conditions, concatenation, functions, assignments within `if`, lists/dictionaries/objects | Not implemented | Only supported simple atomic comparisons and boolean operations are converted. |
|
||||
| Bare `req.http.Cookie`, `req.http.Authorization` | Supported | Tests header presence. A nonempty header name variable is not a test of cookie *content*. |
|
||||
|
||||
### Header-field nuance
|
||||
|
||||
`req.http.Cookie ~ "^(?:__cf_bm|...)=[^;]*$"` is safe as an **entire-header** technical-cookie allowlist only if every physical `Cookie` header field is examined. The rule matcher in this patched source joins multiple Cookie fields with `; ` for header-condition evaluation, so a second field containing `session=...` defeats the anchored allowlist. An invalid UTF-8 Cookie value is treated as *present*, preventing the subsequent `if (req.http.Cookie) { return(pass); }` from accidentally treating it as absent.
|
||||
|
||||
Do **not** use an unanchored regex such as `req.http.Cookie ~ "__cf_bm"` with `unset req.http.Cookie;`: that would discard a session cookie merely because a technical cookie was also present.
|
||||
|
||||
## 3. Request-stage statements (`vcl_recv`)
|
||||
|
||||
| Exact statement form | Status | Rule effect and restrictions |
|
||||
|---|---|---|
|
||||
| `return(pass);` | Supported | Cache bypass; terminates applicable request-stage rules and skips `vcl_hash`. |
|
||||
| `return(hash);`, `return(lookup);` | Supported with safety conditions | Explicit lookup; in Varnish-compatibility mode can admit **Cookie-bearing GET/HEAD** requests, partitioned by their remaining Cookie value and with downstream `Vary: Cookie`. Does not override Authorization, unsafe methods, client privacy or disabled cache. |
|
||||
| `unset req.http.Cookie;` | Supported | Removes **every** Cookie value before subsequent rules, origin forwarding and cache key generation. No per-name deletion in imported VCL. |
|
||||
| `set req.http.X-Name = "literal";` | Supported with protected-name list | Changes a safe request header to a constant string. Origin sees the change. Dynamic/compound expressions are not recognized. |
|
||||
| `unset req.http.X-Name;` | Supported with protected-name list | Removes all values of an allowed request header. |
|
||||
| `set req.url = regsuball(req.url, "...", "\\1");` | Restricted | Only a pattern that matches a captured query separator plus a known parameter-name list is converted to `strip_query`; importer warns about separator/empty-value differences. See [VCL details](VCL.md#request-header-changes-scope-and-safeguards). |
|
||||
| `set req.http.Cookie = regsuball(...)`, single-cookie deletion, `regsub()` on cookies | Not implemented | Use graphical **Strip cookies / Keep these cookies** instead. An imported VCL expression will **not** safely delete one cookie from a list. |
|
||||
| `set req.backend_hint`, `set req.method`, `set req.hash`, `set req.http.Authorization` | Unsupported (intentional boundary) | Request origin selection, security identity, method, HTTP framing and credentials remain controlled by RustProxy's normal Vhost/route/auth machinery. |
|
||||
| `return(pipe)`, `return(purge)`, `return(synth(...))`, `return(restart)` | Not implemented | Warnings, not equivalents to `pass` or other rules. |
|
||||
| `return(deliver)` in `vcl_recv` | Not implemented | This is not a supported return target in the request stage. |
|
||||
|
||||
**Protected general request-header edits** include `Authorization`, `Cookie` (except dedicated whole-header removal), `Cache-Control`, `Pragma`, `Host`, `Range`, `If-*`, `Forwarded`, `Via`, `X-Forwarded-*`, `X-Real-IP`, `X-Client-IP`, `True-Client-IP`, `CF-Connecting-IP`, `Proxy-*`, `Sec-*`, `X-RustProxy-*`, `Content-Type`, `Expect` and the framing/proxy headers in section 6. Such edits are rejected on rule validation, including in imported VCL; valid neighboring actions are still imported.
|
||||
|
||||
## 4. Hash-stage statements (`vcl_hash`)
|
||||
|
||||
| Exact statement | Status | Effect |
|
||||
|---|---|---|
|
||||
| `hash_data(req.url);` | Supported no-op | URL including query already participates in RustProxy's base key. |
|
||||
| `hash_data(req.http.Host);` | Supported no-op | Normalized request authority and vhost isolation already participate in the cache key. |
|
||||
| `hash_data(req.http.X-Device);` | Supported | Adds a request-header value to the internal variant key; `Vary: X-Device` is **not** automatically emitted. |
|
||||
| `hash_data(regsub(req.http.Cookie, ...))` | Not implemented | The graphical editor has a separate **Hash cookie** action; it is not a faithful VCL expression importer. |
|
||||
| `hash_data(client.ip)`, arithmetic/concatenation, VMOD expressions or multiple arguments | Not implemented | Generates warning. |
|
||||
| `hash_data(...)` inside `vcl_recv` | Not implemented | Warns: this instruction is only accepted in `vcl_hash`. |
|
||||
|
||||
## 5. Backend-response stage (`vcl_backend_response`, `vcl_fetch`)
|
||||
|
||||
| Statement | Status | Cache/storage effect |
|
||||
|---|---|---|
|
||||
| `set beresp.ttl = 30s;` | Supported | Freshness override in seconds, bounded by configured limits; recognized units `ms`, `s`, `m`, `h`, `d`, `w`, `y`, plus bare seconds. Rounded to full seconds. Does **not** rewrite `Cache-Control` for browsers. |
|
||||
| `set beresp.grace = 5m;` | Supported | Grace override, within RustProxy limits; not Varnish's complete grace/keep lifecycle. |
|
||||
| `set beresp.uncacheable = true;` | Supported | Prohibits shared storage for the matching response. |
|
||||
| `set beresp.uncacheable = false;` | Supported, RustProxy-specific | Reverses **an earlier cache-rule-induced** no-store action. Does not nullify origin `private`, `no-store`, `Set-Cookie` or another admission barrier. |
|
||||
| `set beresp.http.X-Name = "literal";` | Supported with protected-name list | Overwrites the origin header **before** storage planning and before delivery. May affect admission if the header is `Cache-Control` or `Vary`. |
|
||||
| `unset beresp.http.X-Name;` | Supported with protected-name list | Removes a header before storage; deleting `Cache-Control: private/no-store` intentionally discards origin policy and can expose sensitive content. |
|
||||
| `unset beresp.http.Set-Cookie;` | Supported, dedicated dangerous exception | Removes upstream `Set-Cookie` before storage policy. Do not use for session-dependent responses. |
|
||||
| `return(pass);`, `return(hit_for_pass);`, `return(uncacheable);` | Restricted conversion | Prevents storage; **no Varnish hit-for-pass object** is created. |
|
||||
| `return(deliver);` | Supported | Stops later rules in the backend-response hook. |
|
||||
| `beresp.keep`, `beresp.do_stream`, `beresp.do_gzip`, `beresp.storage`, `beresp.backend`, `beresp.status`, `beresp.reason`, `beresp.http.Set-Cookie = ...` | Not implemented as VCL assignments | No equivalent imported instruction. HTTP storage/encoding and upstream selection have separate RustProxy controls. |
|
||||
| `return(retry)`, `return(abandon)`, `return(error)`, `return(synth)` | Not implemented | Unsupported return warning. |
|
||||
|
||||
The shared cache stores **HTTP status 200** responses only in this release. A positive TTL for `404`, `301`, `302` or `500` does **not** enable negative/redirect/error-response caching. Requests with `Authorization`, no-store signals, disallowed methods, access restrictions or invalid response headers are not made cacheable simply by a VCL lookup decision.
|
||||
|
||||
## 6. Deliver-stage statements and header protection
|
||||
|
||||
| Statement | Status | Effect |
|
||||
|---|---|---|
|
||||
| `set resp.http.X-Name = "literal";` | Supported with protected-name list | Replaces outgoing header on HIT, MISS or BYPASS. Does not alter the stored metadata or variant. |
|
||||
| `unset resp.http.X-Name;` | Supported with protected-name list | Removes outgoing header only. |
|
||||
| `return(deliver);` | Supported | Stops the remaining deliver-stage rule chain. |
|
||||
| `set resp.status`, `set resp.reason`, dynamic `resp.http.* = req.http.*`, `regsub` on resp headers | Not implemented | No response-body/status rewriting or dynamic expressions through imported VCL. |
|
||||
| `return(synth)`, `return(restart)` | Not implemented | Not equivalent to sending a synthetic response or reprocessing the request. |
|
||||
|
||||
**Headers protected from general backend and deliver edits:** `Connection`, `Content-Length`, `Content-Encoding`, `Content-Range`, `Date`, `Keep-Alive`, `Proxy-Authenticate`, `Proxy-Authorization`, `Set-Cookie`, `TE`, `Trailer`, `Transfer-Encoding`, `Upgrade`, `Host`, `Alt-Svc`. The **only** exception is the dedicated `unset beresp.http.Set-Cookie` action. Other subsystems can regenerate or normalize headers after rules have run. Header names compare case-insensitively; `set` replaces the entire repeated field and `unset` removes all occurrences. `set ... = ""` is not the same as `unset`.
|
||||
|
||||
### `Vary` is supported but phase-sensitive
|
||||
|
||||
| Operation | Internal cache variants | Delivered response | Recommendation |
|
||||
|---|---|---|---|
|
||||
| Origin `Vary: Accept-Encoding, Accept-Language` | Both dimensions retained | Passed downstream | Safe default. |
|
||||
| `set beresp.http.Vary = "Accept-Language";` | **Replaces** all origin dimensions before variant planning | Sends new field unless overridden later | Only if origin truly varies solely by language. |
|
||||
| `unset beresp.http.Vary;` | Removes variation requirements **before** admission | Usually removed downstream | Unsafe for personalized/encoded variants. |
|
||||
| `set resp.http.Vary = "Accept-Language";` | **No change** to stored variants | Overrides outgoing field only | Avoid mismatch with the actual storage key. |
|
||||
| `unset resp.http.Vary;` | **No change** to stored variants | Removes outgoing field | Can cause downstream CDN/browser variant leakage. |
|
||||
| Global `static_ignore_vary_cookie` on a public static extension | May remove **Cookie only**, after public/fresh/no-Set-Cookie/privacy checks | Qualifying response no longer varies by Cookie | Do not extend to arbitrary Vary dimensions. |
|
||||
|
||||
`Vary: *` is not reusable. All other retained dimensions must match, including the distinction between absent and present-but-empty headers. RustProxy safely normalizes selected list headers (`Accept-Language`, `Accept-Encoding`, `Accept-Charset`, `Accept`), preserving required semantics; it does not treat opaque `User-Agent`, `Origin`, `Cookie` or custom headers as interchangeable. See [RFC 9111 matching](CACHE.md#vary-matching-rfc-9111-41).
|
||||
|
||||
**Do not add a global “Ignore Vary” switch.** It risks wrong content under different encodings, languages, CORS origins, user-agent-specific responses or authenticated contexts. The existing narrowly scoped `Ignore Vary: Cookie for public static assets` option should remain restricted; fix unnecessary `Vary` at the origin when possible.
|
||||
|
||||
## 7. Graphical actions without a faithful imported VCL equivalent
|
||||
|
||||
These capabilities exist in RustProxy's JSON/graphical cache rules but should **not** be inferred to work by pasting arbitrary VCL syntax:
|
||||
|
||||
| Graphical rule/setting | VCL import limitation |
|
||||
|---|---|
|
||||
| Client IP/CIDR condition | `client.ip ~ acl` not imported. |
|
||||
| Path, extension and query-param conditions | Graphical matching is supported; some exported VCL examples are approximations, not guaranteed round-trip. |
|
||||
| Match a cookie by name/value | `req.http.Cookie` regex supports header testing, but the graphical dedicated cookie condition is not a generic VCL parser feature. |
|
||||
| **Strip cookies, keep** selected names | VCL importer accepts only `unset req.http.Cookie` for whole-header removal. |
|
||||
| **Strip query params** or **keep only** listed params | Only a specific tracking-parameter `regsuball(req.url,...)` form is imported, always with a warning. |
|
||||
| **Hash cookie** by name | Graphical-only; `hash_data(regsub(...))` is not imported. |
|
||||
| **Default header** (set if absent) | Available graphically; VCL `if (!resp.http.X) set ...` may import through basic header-existence guards, but exact graphical ownership/precedence is not guaranteed as a round trip. |
|
||||
| **Ignore backend Cache-Control** | Graphical storage-policy override; not the same as a plain VCL `unset beresp.http.Cache-Control`. |
|
||||
| Scoped global rules, per-Vhost rules, ignore global rules | Stored in RustProxy config, not in VCL source text; imported VCL uses the editor's scope. |
|
||||
| Global/per-vhost static Cookie/`Vary` options | Configuration switches, not VCL statements. |
|
||||
|
||||
## 8. Intentionally excluded and otherwise missing Varnish functionality
|
||||
|
||||
| Feature | Classification | Rationale / alternative |
|
||||
|---|---|---|
|
||||
| Full VCL execution engine and arbitrary VMODs/C modules | **Intentional architectural boundary** | Only validated JSON cache rules execute. Configure supported proxy features through their native Settings/Vhost editor. |
|
||||
| Mutating authentication, identity, transport framing and protected request headers through cache VCL | **Intentional safety boundary** | Prevents bypassing access control, spoofing, cache-policy restrictions or invalid HTTP framing. |
|
||||
| Rewriting raw `Cookie` by broad regex or partially deleting cookies through imported VCL | **Intentional narrow importer** | No unsafe best-effort translation; use full-header `unset` only after an anchored allowlist, or use the graphical cookie-allowlist action for a reviewed policy. |
|
||||
| Varnish hit-for-pass / hit-for-miss objects and `beresp.keep` | **Intentionally not imported** | RustProxy has its own miss collapsing, revalidation and temporary uncacheable-fill handling; these are not Varnish object types. |
|
||||
| Custom backend/ACL/probe definitions in imported VCL | **Intentional configuration boundary** | Configure those as RustProxy backends/ACL profiles/health checks. The source blocks are explicitly warned/skipped. |
|
||||
| Unsafe or unsupported `return(pipe/restart/purge/synth)` | **Not implemented by VCL importer** | HTTP tunneling, administrative purge, synthetic responses and routing use separate native mechanisms, where available. |
|
||||
| Storing 3xx, 4xx and 5xx as shared cache objects | **Not implemented** | Status 200 only; no negative-cache guarantee. |
|
||||
| Varnish ESI, VCL body manipulation, edge includes, custom streaming hooks | **Not implemented** | No VCL capability to parse/modify response bodies. Use separate native transforms only where explicitly supported. |
|
||||
| Varnish backend retries, directors, storage stevedores, clustering/sharding via VCL | **Not implemented as VCL** | RustProxy has independent load balancing/upstream pools and HOT/COLD storage. |
|
||||
| Dynamic expressions, direct filesystem calls, networking from VCL, custom system functions | **Not implemented by design of the rule model** | No executable user-defined code or side effects at the VCL layer. |
|
||||
| Exact VCL export/import round-trip | **Not supported** | Export is an explanatory preview. Back up canonical JSON/configuration instead. |
|
||||
|
||||
The labels above distinguish explicit product limits from missing work; **not implemented** does *not* assert that a future release will implement a feature.
|
||||
|
||||
## 9. Limits, validation and test plan
|
||||
|
||||
| Limit/condition | Implemented boundary |
|
||||
|---|---|
|
||||
| VCL source length | **256 KiB** maximum. |
|
||||
| Rules | **128** compiled rules per applicable rule list. |
|
||||
| Rule conditions/actions | Up to **16** conditions and **16** actions per rule. Long supported action sequences are split as needed; branch expansion can hit limits earlier. |
|
||||
| Rule values | Up to **64** values per condition, **512 bytes** each. |
|
||||
| Regex program budget | Up to **512 bytes per condition value**; compiled regex builder has **1 MiB** NFA/DFA budgets (`64 KiB × 16`). Invalid/overcomplex expressions are rejected. |
|
||||
| TTL/grace | Whole-second setting subject to maximum **365 days** and effective cache settings. |
|
||||
| Origin status | **200** required for shared storage. Other responses can still receive appropriate header edits. |
|
||||
| Import warnings | Need explicit review and acceptance in the UI; never treat warnings as a successful, equivalent conversion. |
|
||||
|
||||
### Regression checklist for a deployment
|
||||
|
||||
1. Import the candidate VCL and require **no unexpected warnings**. Inspect the generated rules in the appropriate global/Vhost/Docker scope.
|
||||
2. Test GET/HEAD with no Cookie, only technical CDN cookies, mixed technical + `session`, multiple physical Cookie lines, and `Authorization`.
|
||||
3. Test protected paths, POST/PUT, invalid Vary, `Vary: *`, `Set-Cookie`, `Cache-Control: private/no-store/no-cache` and responses other than 200.
|
||||
4. Verify both **cached** and **delivered** `Vary` behavior for `Accept-Encoding`, `Accept-Language`, `Origin` and any origin-defined custom dimension.
|
||||
5. On a real, authorized test origin send two identical requests to compare MISS/HIT and a changed Vary dimension to ensure distinct variants. The rule tester **cannot replace** this test.
|
||||
6. For Docker services, repeat after a container disappears and returns, checking the same saved Vhost assignment and the Cache/Traffic scope labels.
|
||||
|
||||
### Included opt-in CDN cookie policy
|
||||
|
||||
The source file [`examples/vcl/cdn-technical-cookies.vcl`](../examples/vcl/cdn-technical-cookies.vcl) and the **CDN technical cookies** cache-rule template provide the same basic safe policy: bypass unsafe methods, sensitive paths and Authorization; strip Cookie only when **all cookies** are in a known allowlist; otherwise bypass. The list includes Cloudflare (`__cf_bm`, `cf_clearance`, `_cfuvid`, `__cfruid`, `__cfseq`) and Akamai (`_abck`, `ak_bmsc`, `bm_sz`, `bm_sv`). Review the list for your origin and CDN challenge flow: some technical/security cookies are needed by the origin and **must not** be stripped in those deployments. This policy is **opt-in**; it does not change the default behavior of existing Vhosts.
|
||||
|
||||
The source contains a Rust regression test (`src/cache/rules_tests.rs`) exercising import and per-request evaluation, plus a Node frontend template contract test (`tests/js/cdn-cookie-template.cjs`). A JavaScript-only test is **not** evidence that the Rust executable compiled or that a real proxy backend was tested.
|
||||
@@ -0,0 +1,587 @@
|
||||
# VCL cookbook: concrete use cases and HTTP traffic scenarios
|
||||
|
||||
**Target:** RustProxy **0.39.0** with the Docker Cache/Traffic and CDN cookie patch. This guide documents the *actual importer* (`src/cache/vcl.rs`), validated cache-rule actions (`src/cache/rules.rs`), and shared-cache admission documented in [Cache](CACHE.md). It is **not** a full Varnish implementation or a promise of exact Varnish semantics.
|
||||
|
||||
Read together with [VCL compatibility](VCL.md) and the [supported/unsupported capability matrix](VCL_SUPPORT_MATRIX.md). The examples are **separate policies**, not one file that should be imported wholesale. Copy one recipe into the correct Vhost scope, then reconcile it with existing global/local rules; **never paste contradictory `return(pass)` policies together without reviewing rule order**.
|
||||
|
||||
## A. How to use the recipes
|
||||
|
||||
1. Pick a **reverse-proxy HTTP Vhost** (ordinary Vhost or Docker vhost). Open its **Cache rules** editor. For site-wide rules use **Settings → Cache → Rules**, but prefer a local scope for policies about one application.
|
||||
2. Enable the global cache and, where intended, the effective per-Vhost cache policy. Check fallback TTL, Varnish-compatible vs strict RFC mode, static-cookie settings, origin response headers and maximum object size. A VCL `return(hash)` **cannot** enable a disabled cache.
|
||||
3. Import the VCL file in the **VCL import** dialog. RustProxy translates it to graphical rules. It does **not** execute a VCL interpreter. Review every generated rule and warning. The importer pauses on warnings; **Add partial import (reviewed)** is a separate explicit step, and the configuration still needs to be saved.
|
||||
4. Use **Test a request** with method, URL, request headers and simulated backend status/headers; confirm which rule matched and whether a terminal `return(pass)` was produced. Test both **global** and **local** rule precedence. A rule preview is **not** a live cache HIT test.
|
||||
5. Run two real identical GET requests through the proxy. Inspect `Cache-Status` (RFC 9211), optionally `X-Cache`/`X-Cache-Reason`, and the delivered `Vary`/`Cache-Control`. Warm a disposable test URL; remove cached objects after changing privacy rules.
|
||||
|
||||
### Terminology in this guide
|
||||
|
||||
| Label | Meaning |
|
||||
|---|---|
|
||||
| **PASS / BYPASS** | Request uses the backend without shared-cache lookup (or fails normal eligibility checks). A response-stage no-store rule can also prevent a MISS from being stored. |
|
||||
| **MISS** | Eligible lookup found no reusable fresh object; origin response is fetched. A MISS does **not** prove that the response was stored. |
|
||||
| **HIT** | An eligible subsequent request uses a fresh matching object, if admission, freshness, storage, and `Vary` conditions all succeeded. |
|
||||
| **STALE / REVALIDATED** | RustProxy's independent grace/stale/conditional machinery may respond without a fresh HIT. Availability and labeling depend on configuration. |
|
||||
| **Origin contract** | Conditions the application must guarantee (public identical body/headers, required `Vary`, validators, no session dependence). VCL does not verify that promise. |
|
||||
|
||||
**Always preserve:** authentication and authorization, session boundaries, private/no-store responses, `Set-Cookie`, client request cache-control and true representation dimensions. If a backend decides which user sees which data, use **PASS** instead of trying to cache it by Cookie or an untrusted synthetic header.
|
||||
|
||||
## B. Choose an appropriate policy
|
||||
|
||||
| Traffic/application | Recommended recipe or native setting | What it can do | What it does **not** do |
|
||||
|---|---|---|---|
|
||||
| CMS articles or a public catalog | [Public catalog](#2-public-catalog-with-explicit-short-ttl) | Cache genuinely shared 200 GETs, set TTL/grace | Force storage of `private`, `Set-Cookie` or 404 |
|
||||
| Public JSON endpoint for prices/stock | [Public JSON API](#3-public-get-json-api) | Short-lived shared cache | Cache credentialed/private API responses |
|
||||
| Admin, login, checkout, user dashboard | [Private routes](#1-exclude-private-routes-and-unsafe-methods) | Bypass shared cache | Replace ACL, OIDC, Basic Auth, app permissions |
|
||||
| Cloudflare/Akamai technical cookies | [CDN cookie allowlist](#4-cdn-technical-cookies-without-dropping-sessions) | Strip an **entire** allowlisted Cookie header | Partially delete one Cookie from a mixed list |
|
||||
| Public CSS, JS, fonts, images | [Static assets](#5-static-assets-and-vary-cookie) + native static settings | Strip request Cookie if proven safe; optional **conditional** `Vary: Cookie` treatment | Override any other arbitrary `Vary` dimension |
|
||||
| Multilingual catalog | [Language variants](#6-language-specific-representations) | Preserve origin `Vary: Accept-Language` and separate variants | Automatically translate or change language |
|
||||
| Low-cardinality public A/B content | [A/B variants](#7-low-cardinality-public-ab-variants) | Add internal header dimension via `vcl_hash` | Write `Vary` for downstream caches |
|
||||
| Server-sent events, webhook traffic, transient errors | [No-store](#8-streaming-webhooks-and-origin-errors) | PASS streaming paths and prevent storage | Retry origins, stream hooks, generate synthetic errors |
|
||||
| Remove internal diagnostics from the response | [Header hygiene](#9-safe-request-and-delivery-header-edits) | Change permitted request/delivery headers | Modify body, protected headers or cache admission at delivery |
|
||||
| Remove tracking parameters from cache identity | [Query rewrite](#10-tracking-query-normalization-restricted) or graphical Strip query | Drop approved params after URL normalization | Import arbitrary `regsub` or preserve regex URL semantics exactly |
|
||||
| Origin sets irrelevant `Set-Cookie` on public SVG | [Advanced public cookie cleanup](#11-advanced-removing-origin-set-cookie-high-risk) | Remove it before storage | Prove it was not needed for identity/session |
|
||||
| CORS responses differentiated by `Origin` | Origin's `Vary: Origin` | Keep origins separate | Safely collapse all origins into one cached response |
|
||||
| Cache error pages/redirects (`404`, `301`, `302`) | **Not supported** | No cache storage in 0.39.0 | Invent negative/redirect-cache TTL via VCL |
|
||||
| IP ranges, backend routing, purge, TLS security | Native ACL/Vhost/Cache API settings | Dedicated supported configuration | Import ACL/director/`return(purge)` as executable VCL |
|
||||
|
||||
## C. Copy-and-import VCL recipes
|
||||
|
||||
All full examples below use only source syntax understood by the RustProxy importer, **except recipe 10, whose restricted conversion deliberately emits a warning**. The advanced Set-Cookie example is syntactically supported but dangerous without a verified public origin contract.
|
||||
|
||||
### 1. Exclude private routes and unsafe methods
|
||||
|
||||
**Goal:** Keep administration, accounts, cart, checkout, webhooks, cookies and credentials away from shared cache.
|
||||
|
||||
**Expected traffic:** `POST /webhook` and `GET /account/orders` → PASS; `GET /catalog` with a session Cookie → PASS.
|
||||
|
||||
**Prerequisites:** Apply to relevant HTTP reverse-proxy Vhosts; configure app authentication separately.
|
||||
|
||||
**Caveat:** There is no final `return(hash)`; other eligible routes retain normal RustProxy policy and any other saved rules.
|
||||
|
||||
Source: [`examples/vcl/private-routes-bypass.vcl`](../examples/vcl/private-routes-bypass.vcl).
|
||||
|
||||
```vcl
|
||||
// Defensive exclusions for an existing HTTP reverse-proxy vhost.
|
||||
// Does not opt in to caching for other routes.
|
||||
sub vcl_recv {
|
||||
if (req.method != "GET" && req.method != "HEAD") {
|
||||
return(pass);
|
||||
}
|
||||
if (req.url ~ "^/(admin|api/private|account|auth|login|logout|checkout|cart|dashboard|webhook)(/|[?]|$)") {
|
||||
return(pass);
|
||||
}
|
||||
if (req.http.Authorization) {
|
||||
return(pass);
|
||||
}
|
||||
if (req.http.Cookie) {
|
||||
return(pass);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Public catalog with explicit short TTL
|
||||
|
||||
**Goal:** Allow only anonymous GET/HEAD for `/catalog`, with 120-second origin-response freshness and 20-second grace.
|
||||
|
||||
**Expected traffic:** First eligible GET is typically MISS; a repeated fresh identical GET may be HIT. `POST /catalog` and `GET /catalog` with a Cookie → PASS.
|
||||
|
||||
**Prerequisites:** The origin returns an actually public representation with `Cache-Control: public, max-age=120`, HTTP 200, no `Set-Cookie` and correct `Vary`.
|
||||
|
||||
**Caveat:** The TTL rule may override a shorter origin TTL. Avoid deploying against pages with fluctuating stock, sessions, authorization or incorrectly marked public content.
|
||||
|
||||
Source: [`examples/vcl/public-catalog.vcl`](../examples/vcl/public-catalog.vcl).
|
||||
|
||||
```vcl
|
||||
// Cache only demonstrably public catalog pages. The origin must supply
|
||||
// Cache-Control: public, max-age=120 and must not vary by user/session.
|
||||
sub vcl_recv {
|
||||
if (req.method != "GET" && req.method != "HEAD") {
|
||||
return(pass);
|
||||
}
|
||||
if (req.http.Authorization || req.http.Cookie) {
|
||||
return(pass);
|
||||
}
|
||||
if (req.url ~ "^/catalog(/|[?]|$)") {
|
||||
return(hash);
|
||||
}
|
||||
return(pass);
|
||||
}
|
||||
|
||||
sub vcl_backend_response {
|
||||
if (bereq.url ~ "^/catalog(/|[?]|$)" && beresp.status == 200 && beresp.http.Cache-Control ~ "(^|,) *public(,|$)") {
|
||||
set beresp.ttl = 120s;
|
||||
set beresp.grace = 20s;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Public GET JSON API
|
||||
|
||||
**Goal:** Cache a controlled, anonymous JSON API for 15 seconds, with 5-second grace.
|
||||
|
||||
**Expected traffic:** `GET /api/public/list` can MISS→HIT; `GET /api/private/me`, `POST /api/public/list` or a request with `Authorization` bypasses.
|
||||
|
||||
**Prerequisites:** Origin returns JSON, 200 and explicit `Cache-Control: public`, with no session dependence; all important `Vary` fields remain intact.
|
||||
|
||||
**Caveat:** A response such as `private`, `no-store`, `Set-Cookie` or invalid `Vary` remains ineligible. Do not treat public API as all API endpoints.
|
||||
|
||||
Source: [`examples/vcl/public-json-api.vcl`](../examples/vcl/public-json-api.vcl).
|
||||
|
||||
```vcl
|
||||
// GET-only shared caching for /api/public. Other API routes bypass.
|
||||
// The origin must mark genuinely public JSON responses as such.
|
||||
sub vcl_recv {
|
||||
if (req.method != "GET" && req.method != "HEAD") {
|
||||
return(pass);
|
||||
}
|
||||
if (req.http.Authorization || req.http.Cookie) {
|
||||
return(pass);
|
||||
}
|
||||
if (req.url ~ "^/api/public(/|[?]|$)") {
|
||||
return(hash);
|
||||
}
|
||||
return(pass);
|
||||
}
|
||||
|
||||
sub vcl_backend_response {
|
||||
if (bereq.url ~ "^/api/public(/|[?]|$)" && beresp.status == 200 && beresp.http.Content-Type ~ "^application/json" && beresp.http.Cache-Control ~ "(^|,) *public(,|$)") {
|
||||
set beresp.ttl = 15s;
|
||||
set beresp.grace = 5s;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4. CDN technical cookies without dropping sessions
|
||||
|
||||
**Goal:** Ignore only known technical Cloudflare/Akamai cookies while keeping real sessions out of shared cache.
|
||||
|
||||
**Expected traffic:** `Cookie: __cf_bm=a; _cfuvid=b` → remove Cookie, eligible for lookup; `Cookie: __cf_bm=a; session=s` → PASS.
|
||||
|
||||
**Prerequisites:** Review the allowlisted names with your CDN provider and origin. Verify the origin does not need these cookie values for bot/challenge flow.
|
||||
|
||||
**Caveat:** Whole-header anchored matching is intentional. Do not replace it with an unanchored test for `__cf_bm`. Do not add load-balancer affinity, challenge, or application cookies automatically.
|
||||
|
||||
Source: [`examples/vcl/cdn-technical-cookies.vcl`](../examples/vcl/cdn-technical-cookies.vcl).
|
||||
|
||||
```vcl
|
||||
// Optional template: only shared/public content independent of these cookies.
|
||||
// Cloudflare: __cf_bm, cf_clearance, _cfuvid, __cfruid, __cfseq
|
||||
// Akamai: _abck, ak_bmsc, bm_sz, bm_sv
|
||||
// Security cookies can be needed for bot challenges; review before enabling.
|
||||
sub vcl_recv {
|
||||
if (req.method != "GET" && req.method != "HEAD") {
|
||||
return(pass);
|
||||
}
|
||||
if (req.url ~ "^/(admin|api|auth|login|logout|panel|konto|dashboard)(/|[?]|$)") {
|
||||
return(pass);
|
||||
}
|
||||
if (req.http.Authorization) {
|
||||
return(pass);
|
||||
}
|
||||
// Match the complete Cookie header, not one cookie within it.
|
||||
if (req.http.Cookie ~ "^(?:__cf_bm|cf_clearance|_cfuvid|__cfruid|__cfseq|_abck|ak_bmsc|bm_sz|bm_sv)=[^;]*(?:;[ \t]*(?:__cf_bm|cf_clearance|_cfuvid|__cfruid|__cfseq|_abck|ak_bmsc|bm_sz|bm_sv)=[^;]*)*$") {
|
||||
unset req.http.Cookie;
|
||||
}
|
||||
if (req.http.Cookie) {
|
||||
return(pass);
|
||||
}
|
||||
return(hash);
|
||||
}
|
||||
```
|
||||
|
||||
### 5. Static assets and Vary: Cookie
|
||||
|
||||
**Goal:** Remove all Cookie headers **only** from independently verified public `/assets` images/fonts/scripts/styles.
|
||||
|
||||
**Expected traffic:** `GET /assets/site.css` with Cookie may use a shared key; other paths remain subject to their original cache policy.
|
||||
|
||||
**Prerequisites:** Every byte and relevant response header is the same for guests and logged-in users; origin produces public 200 and valid freshness.
|
||||
|
||||
**Caveat:** VCL does **not** implement an `Ignore Vary: Cookie` instruction. Use **Static & diagnostics** options; these have additional explicit `public`/freshness/no-Set-Cookie/privacy checks. A session-aware image must not use this recipe.
|
||||
|
||||
Source: [`examples/vcl/static-assets-public.vcl`](../examples/vcl/static-assets-public.vcl).
|
||||
|
||||
```vcl
|
||||
// Optional: remove ALL request cookies for public, identity-independent
|
||||
// assets under /assets. Origin must never use a session for these assets.
|
||||
// Vary: Cookie removal is NOT accomplished by this VCL. Configure the
|
||||
// native "Ignore Vary: Cookie for public static assets" setting separately.
|
||||
sub vcl_recv {
|
||||
if (req.method != "GET" && req.method != "HEAD") {
|
||||
return(pass);
|
||||
}
|
||||
if (req.url ~ "^/assets/.*[.](css|js|png|jpg|jpeg|svg|woff2)([?]|$)") {
|
||||
if (req.http.Authorization) {
|
||||
return(pass);
|
||||
}
|
||||
unset req.http.Cookie;
|
||||
return(hash);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 6. Language-specific representations
|
||||
|
||||
**Goal:** Preserve the origin-defined language dimension rather than flattening it with a header rewrite.
|
||||
|
||||
**Expected traffic:** `Accept-Language: pl` and `Accept-Language: en` are distinct variants **if the origin sends `Vary: Accept-Language`**.
|
||||
|
||||
**Prerequisites:** The backend really changes representations by language and sends `Vary: Accept-Language` **plus** any other dimensions (e.g. `Accept-Encoding`).
|
||||
|
||||
**Caveat:** Do not set `beresp.http.Vary = "Accept-Language"` if the origin also varies by compression, Origin, device or another header.
|
||||
|
||||
Source: [`examples/vcl/language-catalog.vcl`](../examples/vcl/language-catalog.vcl).
|
||||
|
||||
```vcl
|
||||
// Origin responsibility: return Vary: Accept-Language (plus any other real
|
||||
// dimensions such as Accept-Encoding), public freshness and no Set-Cookie.
|
||||
// Do not replace the origin Vary list with a single dimension.
|
||||
sub vcl_recv {
|
||||
if (req.method != "GET" && req.method != "HEAD") {
|
||||
return(pass);
|
||||
}
|
||||
if (req.http.Authorization || req.http.Cookie) {
|
||||
return(pass);
|
||||
}
|
||||
if (req.url ~ "^/translations(/|[?]|$)") {
|
||||
return(hash);
|
||||
}
|
||||
return(pass);
|
||||
}
|
||||
|
||||
sub vcl_backend_response {
|
||||
if (bereq.url ~ "^/translations(/|[?]|$)" && beresp.status == 200 && beresp.http.Cache-Control ~ "(^|,) *public(,|$)") {
|
||||
set beresp.ttl = 60s;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 7. Low-cardinality public A/B variants
|
||||
|
||||
**Goal:** Demonstrate `vcl_hash` with one explicit request-header value for public A/B experiment content.
|
||||
|
||||
**Expected traffic:** `X-Experiment: A` and `X-Experiment: B` should partition the internal key; any other value bypasses.
|
||||
|
||||
**Prerequisites:** Clients send the header themselves (also to downstream caches); the origin returns `Vary: X-Experiment` and does not personalize by user.
|
||||
|
||||
**Caveat:** `hash_data` does not send `Vary` to clients; missing Vary can leak a variant through another cache. Keep a strict finite value list to avoid unbounded cardinality.
|
||||
|
||||
Source: [`examples/vcl/experiment-variants.vcl`](../examples/vcl/experiment-variants.vcl).
|
||||
|
||||
```vcl
|
||||
// Controlled, PUBLIC A/B variants: client sends X-Experiment: A or B.
|
||||
// Origin must also return Vary: X-Experiment, preserve other Vary fields,
|
||||
// and never associate this header with credentials or private data.
|
||||
sub vcl_recv {
|
||||
if (req.method != "GET" && req.method != "HEAD") {
|
||||
return(pass);
|
||||
}
|
||||
if (req.http.Authorization || req.http.Cookie) {
|
||||
return(pass);
|
||||
}
|
||||
if (req.url ~ "^/experiment(/|[?]|$)") {
|
||||
if (req.http.X-Experiment ~ "^(A|B)$") {
|
||||
return(hash);
|
||||
}
|
||||
return(pass);
|
||||
}
|
||||
return(pass);
|
||||
}
|
||||
|
||||
sub vcl_hash {
|
||||
hash_data(req.http.X-Experiment);
|
||||
}
|
||||
```
|
||||
|
||||
### 8. Streaming, webhooks and origin errors
|
||||
|
||||
**Goal:** Avoid caching event streams/webhooks and mark SSE/error responses as uncacheable in the response stage.
|
||||
|
||||
**Expected traffic:** `GET /events` → PASS; an unrelated response with `Content-Type: text/event-stream` → NoStore; status 5xx → NoStore.
|
||||
|
||||
**Prerequisites:** Use native proxy/WebSocket/stream and backend retry configuration for those separate operations.
|
||||
|
||||
**Caveat:** This is not a Varnish `vcl_backend_error`, retry, pipe or stale-if-error implementation. `500` was never eligible for 0.39.0 shared storage anyway.
|
||||
|
||||
Source: [`examples/vcl/stream-and-errors-no-store.vcl`](../examples/vcl/stream-and-errors-no-store.vcl).
|
||||
|
||||
```vcl
|
||||
// Defense in depth for streaming and transient backend responses.
|
||||
// Does not implement retries, synthetic error handling or stale-if-error.
|
||||
sub vcl_recv {
|
||||
if (req.url ~ "^/(events|stream|webhook)(/|[?]|$)") {
|
||||
return(pass);
|
||||
}
|
||||
}
|
||||
|
||||
sub vcl_backend_response {
|
||||
if (beresp.http.Content-Type ~ "^text/event-stream") {
|
||||
set beresp.uncacheable = true;
|
||||
return(deliver);
|
||||
}
|
||||
if (beresp.status >= 500) {
|
||||
set beresp.uncacheable = true;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 9. Safe request and delivery header edits
|
||||
|
||||
**Goal:** Remove a non-essential request header, set a constant origin-visible marker, remove an internal response header and tag delivery.
|
||||
|
||||
**Expected traffic:** `GET /catalog` forwards `X-Edge-Policy: catalog-v1`; a downstream response no longer exposes `X-Debug`.
|
||||
|
||||
**Prerequisites:** Changes only use permitted header names. Test both Cache HIT and MISS and the origin request.
|
||||
|
||||
**Caveat:** Deliver-stage edits happen after cache selection; they cannot rescue an ineligible response or safely delete `Vary` for all downstream caches.
|
||||
|
||||
Source: [`examples/vcl/headers-and-diagnostics.vcl`](../examples/vcl/headers-and-diagnostics.vcl).
|
||||
|
||||
```vcl
|
||||
// Request header sanitation (safe, ordinary representation headers only).
|
||||
// Deliver mutations do not change the object stored in cache.
|
||||
sub vcl_recv {
|
||||
if (req.url ~ "^/catalog(/|[?]|$)") {
|
||||
unset req.http.X-Marketing-Source;
|
||||
set req.http.X-Edge-Policy = "catalog-v1";
|
||||
}
|
||||
}
|
||||
|
||||
sub vcl_deliver {
|
||||
if (req.url ~ "^/catalog(/|[?]|$)") {
|
||||
unset resp.http.X-Debug;
|
||||
set resp.http.X-Edge-Policy = "catalog-v1";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 10. Tracking-query normalization (restricted)
|
||||
|
||||
**Goal:** Normalize a small allowlist of proven non-semantic tracking parameters on `/landing`.
|
||||
|
||||
**Expected traffic:** `GET /landing?utm_source=ad` can map to a query-stripped cache target after rule conversion.
|
||||
|
||||
**Prerequisites:** The application guarantees these parameters never affect body, localization, cookies or redirects; inspect the exact generated Strip query rule.
|
||||
|
||||
**Caveat:** **An import warning is expected.** RustProxy converts the recognized `regsuball` to a native query action with potentially different separators/empty-value behavior. Review before **Add partial import (reviewed)**. Prefer the graphical action for repeatable configuration.
|
||||
|
||||
Source: [`examples/vcl/tracking-query-restricted.vcl`](../examples/vcl/tracking-query-restricted.vcl).
|
||||
|
||||
```vcl
|
||||
// Demonstrates the ONLY recognized req.url regsuball form.
|
||||
// Import WILL WARN: converted to native strip_query with potentially
|
||||
// different URL separator/empty-value normalization. Review and accept
|
||||
// partial import only if the original URL parameters have no origin impact.
|
||||
sub vcl_recv {
|
||||
if (req.url ~ "^/landing([?]|$)") {
|
||||
set req.url = regsuball(req.url, "([?&])(utm_source|utm_medium|gclid)=[^&]*", "\1");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 11. Advanced: removing origin Set-Cookie (high risk)
|
||||
|
||||
**Goal:** Demonstrate the dedicated backend `unset beresp.http.Set-Cookie` escape hatch for one verified public SVG.
|
||||
|
||||
**Expected traffic:** `GET /public/banner.svg` may become storable if that was its only storage barrier and all other checks permit it.
|
||||
|
||||
**Prerequisites:** You have independently verified that the exact URL, body and response headers are identical for every visitor and that removing the cookie will not affect session, security or challenge behavior.
|
||||
|
||||
**Caveat:** **Never apply globally.** Removing the origin cookie and thereby enabling public storage can disclose personalized content. A rule that adds TTL does not bypass other privacy barriers.
|
||||
|
||||
Source: [`examples/vcl/advanced-set-cookie-removal.vcl`](../examples/vcl/advanced-set-cookie-removal.vcl).
|
||||
|
||||
```vcl
|
||||
// ADVANCED / HIGH RISK. Only for a verified identical public representation.
|
||||
// Removes Set-Cookie before storage and before forwarding the origin response.
|
||||
// NEVER apply to login, accounts, cart, personalized JSON or CSRF flows.
|
||||
sub vcl_backend_response {
|
||||
if (bereq.url ~ "^/public/banner[.]svg([?]|$)" && beresp.status == 200 && beresp.http.Cache-Control ~ "(^|,) *public(,|$)") {
|
||||
unset beresp.http.Set-Cookie;
|
||||
set beresp.ttl = 1h;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## D. Real HTTP traffic: what is handled and what is not
|
||||
|
||||
The outcomes below describe **decision paths**, not a guaranteed X-Cache label: proxy route exclusions, access checks, configuration, origin responses, object sizes, validators, time, and storage limits still apply. The word **eligible** means the request may look up or populate cache if all other conditions succeed.
|
||||
|
||||
### D1. Requests, cookies and authorization
|
||||
|
||||
| Incoming request | Example policy | Decision | Important detail |
|
||||
|---|---|---|---|
|
||||
| `GET /catalog/item/1` (anonymous) | Public catalog | Eligible lookup | First fetch usually MISS; second may HIT. |
|
||||
| `HEAD /catalog/item/1` | Public catalog | Eligible method | Verify real HEAD behavior rather than assuming it fills the same object as GET. |
|
||||
| `POST /catalog/item/1` | Public catalog | PASS | VCL does not override unsafe-method restriction. |
|
||||
| `PUT /api/public/item/1` | Public API | PASS | Mutations do not become cacheable. |
|
||||
| `GET /account/orders` | Private routes | PASS | Authentication and authorization are enforced outside VCL. |
|
||||
| `GET /api/public/list` without credentials | Public API | Eligible lookup | Only public JSON 200 has the example 15-second TTL. |
|
||||
| `GET /api/private/me` | Public API | PASS | Path excluded even without Cookie. |
|
||||
| `GET /catalog`, `Authorization: Bearer ...` | Catalog | PASS | Credentialed requests are excluded by code and cache safety checks. |
|
||||
| `GET /catalog`, `Cookie: session=abc` | Catalog/CDN | PASS | No session cookie stripping. |
|
||||
| `GET /catalog`, `Cookie: __cf_bm=a` | CDN cookie allowlist | Strip Cookie; eligible | Origin receives no Cookie; confirm CDN challenge behavior. |
|
||||
| `Cookie: __cf_bm=a; cf_clearance=b` | CDN cookie allowlist | Strip whole Cookie header | Only exact allowlisted cookie names pass. |
|
||||
| `Cookie: __cf_bm=a; session=b` | CDN cookie allowlist | PASS | Even one non-allowlisted name prevents removal. |
|
||||
| Two physical Cookie fields, one technical and one session | CDN cookie allowlist | PASS | Patched matcher examines combined cookie values. |
|
||||
| `GET /assets/site.css`, arbitrary Cookie | Public static | Strip Cookie **if verified safe** | Separate native `Vary: Cookie` setting has additional conditions. |
|
||||
| `GET /assets/user-avatar.png`, Cookie | Do **not** use static bypass | PASS recommended | Do not remove session personalization merely due to extension. |
|
||||
| `GET /experiment`, `X-Experiment: A` | A/B variants | Eligible A partition | Origin must emit downstream `Vary: X-Experiment`. |
|
||||
| `GET /experiment`, `X-Experiment: C` | A/B variants | PASS | Unrecognized dimension value intentionally rejected. |
|
||||
| `POST /webhook` | Private / stream | PASS | Rules do not replace request authentication/signature verification. |
|
||||
| `GET /events`, SSE | Stream no-store | PASS | No VCL body streaming/rewrite support. |
|
||||
|
||||
### D2. Origin response and `Vary`
|
||||
|
||||
| Backend sends | RustProxy 0.39.0 consequence | Safety check |
|
||||
|---|---|---|
|
||||
| `200`, public/fresh, no Set-Cookie, valid Vary | Potential shared-store candidate | Response must really be identical for all users. |
|
||||
| `200`, `Cache-Control: private` | Not storable without **dangerous explicit rewrite** | Never rewrite private content to public. |
|
||||
| `200`, `Cache-Control: no-store` | Not storable without **dangerous explicit rewrite** | Do not use header removal to bypass origin policy. |
|
||||
| `200`, `Set-Cookie: session=...` | Not storable normally | Dedicated Set-Cookie removal is high risk. |
|
||||
| `200`, `Vary: Accept-Encoding` | Distinct encoding variants | Do not unset `Vary` to increase HIT rate. |
|
||||
| `200`, `Vary: Accept-Language, Accept-Encoding` | Both dimensions preserved | An overwrite with only language loses encoding correctness. |
|
||||
| `200`, `Vary: Origin` | Different CORS-Origin variants | Do not collapse different allowed origins. |
|
||||
| `200`, `Vary: Cookie` on genuinely public static | Native exception **may** remove Cookie member | Requires configured extension, public positive freshness, no privacy blockers. |
|
||||
| `200`, `Vary: Cookie` on personalized JSON | Preserve or bypass | No universal Ignore Vary switch. |
|
||||
| `200`, `Vary: *` | No reusable cached variant | Rewrite at application if appropriate; do not force-drop. |
|
||||
| `200`, malformed `Vary` | No reusable cached variant | Fix origin response. |
|
||||
| `200`, `no-cache` and validator | Conditional behavior depends on compatibility/fallback | Do not assume TTL or forced HIT. |
|
||||
| `200`, `no-cache` without validator | Compatibility fallback may differ from strict mode | See [Cache mode](CACHE.md); verify selected global/per-Vhost settings. |
|
||||
| `200`, `Content-Type: text/event-stream` | NoStore if SSE recipe applies | No synthetic stream buffering in VCL. |
|
||||
| `200`, `Cache-Control: public, max-age=0` | Not fresh solely because `public` | Short-TTL overrides are a deliberate independent administrative decision. |
|
||||
| `301` / `302` redirect | Not storable | TTL recipe cannot enable redirect caching. |
|
||||
| `404` / `410` missing asset | Not storable | Negative caching not implemented. |
|
||||
| `500` / `502` / `503` error | Not storable | Independently configured stale-if-error may use an **earlier** stored object. |
|
||||
| `304` response to revalidation | Native conditional revalidation | Not a programmable `vcl_hit` / `vcl_miss` callback. |
|
||||
|
||||
### D3. Deployment, Docker, and other edge conditions
|
||||
|
||||
| Situation | Suggested handling | Boundary |
|
||||
|---|---|---|
|
||||
| Docker container restarts and returns | Keep saved per-vhost rules and verify discovered routing after recovery | VCL does not start/recreate containers. |
|
||||
| Docker container disappears | Native health/routing logic; observe possible 503 or eligible stale-if-error | `vcl_backend_error` and VCL retry are unsupported. |
|
||||
| Same path on two unrelated domains | Per-vhost configuration and normalized Host isolation | No cross-vhost shared object or `hash_data(Host)` requirement. |
|
||||
| Cache for only some Docker services | Apply rule to the selected Docker vhost or scoped global rules | Do not paste one global `return(hash)` for all apps. |
|
||||
| Static file served by the **built-in** Web Server or PHP | Use those components' native settings | VCL rule importer is for HTTP reverse-proxy Vhosts. |
|
||||
| Source checks for `Authorization` or TLS client identity | Native auth, ACL and transport security | These cannot be rewritten in cache VCL. |
|
||||
| `Range`, `If-*`, request `Cache-Control: no-store` | Native conditional/range/privacy logic | Request-rule header mutations cannot override protected headers. |
|
||||
| IP/CIDR based cache eligibility | Graphical cache-rule `client_ip` condition or native security ACL | `client.ip ~ my_acl` is **not** importable. |
|
||||
| Tracking params (`utm_*`, `gclid`) | Graphical **Strip query params** with an explicit allowlist | VCL `regsuball` is limited and emits a warning. |
|
||||
| Debug counters and Cache/Traffic lists | Native Cache/Traffic UI and HTTP cache diagnostics | VCL has no log writing, metrics API or custom VMOD. |
|
||||
|
||||
## E. `Vary` decisions: prefer correctness over HIT ratio
|
||||
|
||||
1. **Keep origin `Vary`** unless you can prove it is wrong. RustProxy compares retained dimensions, including `Accept-Language`, `Accept-Encoding`, `Origin`, custom headers and Cookie. It normalizes selected list-valued headers but does not generally discard dimensions.
|
||||
2. If the origin emits an unnecessary `Vary: Cookie` for truly public `.css`/`.png`/`.woff2` files, first try fixing the origin. Otherwise use the **narrow native static-asset option** (configured extensions + public freshness + no Set-Cookie/privacy); do not use `unset beresp.http.Vary`.
|
||||
3. When a service responds differently by language, compression, device, origin or experiment, **retain every actual dimension**. `set beresp.http.Vary = "Accept-Language"` overwrites the whole field; `set resp.http.Vary` changes only delivery and can mislead downstream caches.
|
||||
4. `hash_data(req.http.X-Experiment)` is **internal** to RustProxy. The backend still must send `Vary: X-Experiment` to downstream caches, and clients must actually supply the header to those caches. A header known only to RustProxy cannot safely stand in for a public `Vary` contract.
|
||||
5. Never apply a general `Ignore Vary` switch or remove `Vary: Cookie` for account/avatar, session-protected files, locale-by-Cookie or CORS-by-Origin variants.
|
||||
|
||||
### Example: correctly declared language and encoding variants
|
||||
|
||||
```http
|
||||
GET /translations/home HTTP/1.1
|
||||
Host: public.example.test
|
||||
Accept-Language: pl
|
||||
Accept-Encoding: gzip
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Cache-Control: public, max-age=60
|
||||
Vary: Accept-Language, Accept-Encoding
|
||||
Content-Type: text/html; charset=utf-8
|
||||
```
|
||||
|
||||
A second request with **identical relevant headers** may HIT after a successful fill; changing language or encoding must select a different object or fetch it from the origin. If the origin also varies by `Origin`, the response must include that member too.
|
||||
|
||||
## F. Inspect behavior with curl (staging environment)
|
||||
|
||||
Run against your **own test site** through the configured TLS listener. The hostname, paths and proxy must be replaced with actual test values. These commands use GET (`-o /dev/null -D -`) so the result does not depend on the HEAD method's implementation. Enable RustProxy cache diagnostics if you want `X-Cache` and reason fields; otherwise inspect `Cache-Status` and response headers.
|
||||
|
||||
```sh
|
||||
BASE='https://public.example.test'
|
||||
# Warm a public resource: watch the first response and the repeated one.
|
||||
curl -sS -o /dev/null -D - "$BASE/catalog/item/1"
|
||||
curl -sS -o /dev/null -D - "$BASE/catalog/item/1"
|
||||
|
||||
# Login/session and credential-bearing requests must not be served from shared cache.
|
||||
curl -sS -o /dev/null -D - -H 'Cookie: session=test' "$BASE/catalog/item/1"
|
||||
curl -sS -o /dev/null -D - -H 'Authorization: Bearer test' "$BASE/catalog/item/1"
|
||||
|
||||
# Technical-only cookies vs mixed cookies: inspect origin logs as well.
|
||||
curl -sS -o /dev/null -D - -H 'Cookie: __cf_bm=test' "$BASE/catalog/item/1"
|
||||
curl -sS -o /dev/null -D - -H 'Cookie: __cf_bm=test; session=test' "$BASE/catalog/item/1"
|
||||
|
||||
# Private path and non-GET should be bypassed.
|
||||
curl -sS -o /dev/null -D - "$BASE/account/orders"
|
||||
curl -sS -o /dev/null -D - -X POST "$BASE/api/public/list"
|
||||
|
||||
# Check separate language variants, using an endpoint that really sets Vary.
|
||||
curl -sS -o /dev/null -D - -H 'Accept-Language: pl' "$BASE/translations/home"
|
||||
curl -sS -o /dev/null -D - -H 'Accept-Language: pl' "$BASE/translations/home"
|
||||
curl -sS -o /dev/null -D - -H 'Accept-Language: en' "$BASE/translations/home"
|
||||
|
||||
# A/B: only if the origin varies by X-Experiment and this is genuinely public.
|
||||
curl -sS -o /dev/null -D - -H 'X-Experiment: A' "$BASE/experiment"
|
||||
curl -sS -o /dev/null -D - -H 'X-Experiment: B' "$BASE/experiment"
|
||||
```
|
||||
|
||||
**If a command prints no diagnostic header**, do not assume a HIT or PASS. Re-run with diagnostics enabled or inspect Cache/Traffic counters and origin access logs. Compare two requests to the **same scheme, host, path, query and `Vary` header values**. Changing an identity, method or URL changes the result. Avoid `curl -k` as a testing habit: verify the real TLS certificate.
|
||||
|
||||
### Minimal scenario matrix for the graphical rule tester
|
||||
|
||||
| Test | Request input | Mock origin response | Expected rule-level decision |
|
||||
|---|---|---|---|
|
||||
| Catalog lookup | `GET /catalog/item/1` | `200`, `Cache-Control: public, max-age=120` | Request lookup; backend TTL=120, grace=20. |
|
||||
| Logged-in user | `GET /catalog/item/1`, Cookie `session=abc` | `200`, `Cache-Control: private` | Request PASS; no public storage. |
|
||||
| CDN-only | `GET /catalog/item/1`, Cookie `__cf_bm=abc` | `200`, public | After CDN recipe: Cookie removed; lookup eligible. |
|
||||
| Mixed cookies | `GET /catalog/item/1`, Cookie `__cf_bm=abc; session=abc` | `200`, public | Request PASS; session preserved. |
|
||||
| Public API | `GET /api/public/list` | `200`, JSON, public | Lookup; backend TTL 15 and grace 5. |
|
||||
| Private API | `GET /api/private/me` | `200`, private | Request PASS. |
|
||||
| API mutation | `POST /api/public/list` | `200`, JSON, public | Request PASS. |
|
||||
| Multi-language | `GET /translations/home`, Accept-Language `pl` | `200`, public, Vary: Accept-Language | Eligible variant for `pl`. |
|
||||
| SSE | `GET /events` | `200`, text/event-stream | PASS. |
|
||||
| 404 | `GET /catalog/missing` | `404` | TTL rule not enough to store. |
|
||||
| Backend failure | `GET /catalog/item/1` | `503` | 503 not storable; separate stale policy may apply. |
|
||||
| Tracking-query source | `GET /landing?utm_source=x` | `200`, public | Restricted import warning; review stripped query representation. |
|
||||
|
||||
The tester previews the *cache rules*, including unsaved rules in the active editor. It does not simulate all unsaved global/per-Vhost cache configuration, is not connected to the origin and cannot prove a real HIT.
|
||||
|
||||
## G. Common mistakes and missing functionality
|
||||
|
||||
| Symptom or attempted VCL | Why it fails or is dangerous | Correct approach |
|
||||
|---|---|---|
|
||||
| Import looks successful but nothing changes | Import previews rules; warnings require manual acceptance, and rules still need saving | Inspect converted graph, approve reviewed warnings, save, test live |
|
||||
| `return(hash)` but every request is BYPASS | Cache disabled, credential/route restriction, response no-store/Set-Cookie, request policy, size limits, etc. | Check global + Vhost flags and actual response headers |
|
||||
| A MISS never becomes HIT | MISS may not be stored; TTL 0, invalid Vary, origin private, Set-Cookie, status != 200 | Inspect reason and origin headers; do not force public without proof |
|
||||
| `unset req.http.Cookie` on a header containing session | Removes **all** cookies, including session identity | Use anchored **entire-header** technical allowlist or PASS |
|
||||
| `set req.http.Cookie = regsuball(...)` | Not imported | Graphical **Strip cookies / Keep** names with reviewed scope |
|
||||
| `set req.url = regsub(...)` with arbitrary pattern | Not implemented | Use native path/location routing or the graphical query action |
|
||||
| `client.ip ~ my_acl`, `return(purge)`, `return(synth)` | Unsupported VCL importer actions | Use native ACL/security/purge/route/error configuration |
|
||||
| `set beresp.ttl = 1h` for a 404 | Storage only supports HTTP 200 | No negative-cache feature in this version |
|
||||
| `unset resp.http.Vary` to merge variants | Changes client response, not stored key; breaks downstream caches | Fix origin `Vary` or use strict native public-static Cookie exception |
|
||||
| `unset beresp.http.Cache-Control` or `Set-Cookie` to force HIT | Can turn private data into shared content | Restore origin privacy; do not rewrite session responses |
|
||||
| `hash_data` on request header without downstream Vary | RustProxy partition and client/CDN partition differ | Have the origin send all true `Vary` members |
|
||||
| Need request-body parsing, ESI, backend directors, VMOD, cache-specific custom logging | No VCL interpreter/VMOD/body hook | Configure native features where supported or handle at origin |
|
||||
| Docker vhost does not appear in global scope | Discovery/configuration may have changed; cache target list depends on active inventories | Recheck Docker agent inventory, publish/assignment and Cache target scope |
|
||||
|
||||
## H. Change-management checklist
|
||||
|
||||
- [ ] Select global, manual Vhost or Docker Vhost scope; compare inherited and local rule precedence.
|
||||
- [ ] Confirm backend privacy contract for every URL and Cookie combination.
|
||||
- [ ] Confirm only GET/HEAD are eligible; session and Authorization requests bypass.
|
||||
- [ ] Check HTTP 200 status, freshness, validators, size, response `Cache-Control`, `Set-Cookie` and complete `Vary`.
|
||||
- [ ] Import without unexpected warnings; separately approve any restricted conversion after inspecting graph.
|
||||
- [ ] Save the rules, then test real requests and variants (not only the rule tester).
|
||||
- [ ] Recheck after upstream changes, CDN changes, Docker container recreation and caching-mode changes.
|
||||
- [ ] Invalidate affected existing cache objects when changing privacy, key or `Vary` policy.
|
||||
|
||||
## Further references
|
||||
|
||||
- [Exact VCL support matrix](VCL_SUPPORT_MATRIX.md): supported, restricted, graphical-only, intentional exclusions and absent features.
|
||||
- [VCL import semantics](VCL.md): stage order, header edits, syntactic limits, strict vs compatible behavior.
|
||||
- [HTTP cache](CACHE.md): freshness, static options, `Vary` matching, diagnostics, HOT/COLD, purge and stale handling.
|
||||
- [Docker discovery](DOCKER_DISCOVERY.md): Docker inventory and saved vhost publication lifecycle.
|
||||
- [Cache API](API.md): configuration and cache endpoints.
|
||||
|
||||
**Validation scope:** These are source-reviewed operator examples, not evidence of a full Rust compiler/proxy traffic test. Revalidate against the actual binary and origin before production use.
|
||||
|
||||
Reference in new issue
Block a user