| index 1c48d9a3e..db6140f2c 100644 |
| --- a/internal/edge/demo_traffic_test.go |
| +++ b/internal/edge/demo_traffic_test.go |
| @@ -429,6 +429,64 @@ func TestDemoTrafficReloadAndCacheBypass(t *testing.T) { |
| } |
| } |
| |
| +// TestDemoTrafficPageDiagnostics (final review finding 3): a demo instance's |
| +// response goes through the reload-built proxy, whose response hook takes |
| +// the app's Carlos-Page-Cache into the request's holder and strips it, and |
| +// through the diagnostic writer, so a marked response reaches the visitor |
| +// with Carlos-Cache: bypass and no marker. An unmarked one gets neither. |
| +func TestDemoTrafficPageDiagnostics(t *testing.T) { |
| + e, rt, c := demoTrafficFixture(t, nil) |
| + if err := e.reg.Upsert(rt); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := e.Reload(); err != nil { |
| + t.Fatal(err) |
| + } |
| + up := e.current()[rt.Host] |
| + if up.route.Kind != "instance" { |
| + t.Fatalf("the demo route is a %q", up.route.Kind) |
| + } |
| + wrapped, ok := up.proxy.(assetScrubbedProxy) |
| + if !ok { |
| + t.Fatalf("proxy %T", up.proxy) |
| + } |
| + transport, ok := wrapped.proxy.Transport.(demoBannerTransport) |
| + if !ok { |
| + t.Fatalf("transport %T", wrapped.proxy.Transport) |
| + } |
| + var mark atomic.Value |
| + mark.Store("") |
| + transport.base = roundTripperFunc(func(r *http.Request) (*http.Response, error) { |
| + h := http.Header{"Content-Type": {"text/plain"}, "Cache-Control": {"public, s-maxage=600"}} |
| + if v := mark.Load().(string); v != "" { |
| + h.Set(pageCacheHeader, v) |
| + } |
| + return &http.Response{StatusCode: 200, Header: h, Body: io.NopCloser(strings.NewReader("shop")), Request: r, ContentLength: -1}, nil |
| + }) |
| + wrapped.proxy.Transport = transport |
| + for _, tc := range []struct{ mark, want string }{ |
| + {`on; ignore-cookies="consent"`, "bypass"}, |
| + {"", ""}, |
| + } { |
| + mark.Store(tc.mark) |
| + rec := httptest.NewRecorder() |
| + e.ServeHTTP(rec, httptest.NewRequest("GET", "https://"+rt.Host+"/p", nil)) |
| + if rec.Code != 200 || rec.Body.String() != "shop" { |
| + t.Fatalf("mark %q: %d %q", tc.mark, rec.Code, rec.Body.String()) |
| + } |
| + if got := rec.Header().Values(pageCacheHeader); len(got) != 0 { |
| + t.Fatalf("mark %q: the visitor got the marker %q", tc.mark, got) |
| + } |
| + if got := rec.Header().Get(assetCacheHeader); got != tc.want { |
| + t.Fatalf("mark %q: Carlos-Cache = %q, want %q", tc.mark, got, tc.want) |
| + } |
| + assertDemoPolicy(t, rec.Header()) |
| + } |
| + if c.requests != 2 { |
| + t.Fatalf("counted %d requests", c.requests) |
| + } |
| +} |
| + |
| func TestDemoTrafficPurgeDrainsWriter(t *testing.T) { |
| entered := make(chan struct{}) |
| release := make(chan struct{}) |