This commit is contained in:
Mateusz Gruszczyński committed 2026-11-20 23:14:19 +01:00
1 parent d455028de3
commit 5b2eaaff61
36 files changed
+2544 -102

No files matched your search

+13 -5
View File
@@ -1,6 +1,6 @@
# VCL cookbook: concrete use cases and HTTP traffic scenarios
**Target:** RustProxy **0.39.1** 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.
**Target:** RustProxy **0.39.2** 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**.
@@ -41,7 +41,7 @@ Read together with [VCL compatibility](VCL.md) and the [supported/unsupported ca
| 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.1 | Invent negative/redirect-cache TTL via VCL |
| Cache error pages/redirects (`404`, `301`, `302`) | **Not supported** | No cache storage in 0.39.2 | 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
@@ -182,13 +182,19 @@ sub vcl_recv {
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;
}
// Remaining cookies: Cookie/session guard. RustProxy extension
// return(cookie_pass) bypasses pages like return(pass) but lets public
// static assets use the cache when "Ignore request cookies for static
// files" is on. In stock Varnish use return(pass) here.
if (req.http.Cookie) {
return(pass);
return(cookie_pass);
}
return(hash);
}
```
The final guard uses `return(cookie_pass)`: logged-in pages remain `BYPASS` (`cache_rule_cookie`), while public CSS/JS/images/fonts can be shared under the static cookie policy. Use `return(pass)` there to keep the 0.39.1 behavior. See [decision precedence](CACHE.md#cache-decision-precedence-explicit-pass-and-public-static-assets).
### 5. Static assets and Vary: Cookie
**Goal:** Remove all Cookie headers **only** from independently verified public `/assets` images/fonts/scripts/styles.
@@ -199,6 +205,8 @@ sub vcl_recv {
**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.
**Without stripping cookies:** if your session guards use `return(cookie_pass)` (or the session templates), you do not need this recipe for logged-in users: with **Ignore request cookies for static files** on, public static assets reach the cache while the Cookie is still forwarded, and storage requires an explicitly public backend reply ([shared-static guard](CACHE.md#public-static-assets-with-a-session-cookie)).
Source: [`examples/vcl/static-assets-public.vcl`](../examples/vcl/static-assets-public.vcl).
```vcl
@@ -301,7 +309,7 @@ sub vcl_hash {
**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.1 shared storage anyway.
**Caveat:** This is not a Varnish `vcl_backend_error`, retry, pipe or stale-if-error implementation. `500` was never eligible for 0.39.2 shared storage anyway.
Source: [`examples/vcl/stream-and-errors-no-store.vcl`](../examples/vcl/stream-and-errors-no-store.vcl).
@@ -473,7 +481,7 @@ The outcomes below describe **decision paths**, not a guaranteed X-Cache label:
### D2. Origin response and `Vary`
| Backend sends | RustProxy 0.39.1 consequence | Safety check |
| Backend sends | RustProxy 0.39.2 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. |