edge: an app's 1xx loses the asset vocabulary on every local proxy (asset cache plan 3 final F6)
ModifyResponse never sees an informational response: httputil writes it from its trace callback. Reload now installs every tenant reverse proxy behind assetScrubbedProxy, which hands it an assetInformationalScrub writer (the wrapper the backhaul and the caught fallbacks already use), so the ordinary path, the upgrade branch, the activator and a fill all strip it. ReverseProxy flushes and hijacks through ResponseController, which follows Unwrap, so streaming and upgrades are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+73
−0
internal/edge/asset_far_test.go+50 −0internal/edge/assetcatch.go+13 −0internal/edge/edge.go+10 −0
diff --git a/internal/edge/asset_far_test.go b/internal/edge/asset_far_test.go| index 0278766bf..9cff2b9b3 100644 |
| --- a/internal/edge/asset_far_test.go |
| +++ b/internal/edge/asset_far_test.go |
| @@ -1236,3 +1236,53 @@ func TestFarColdMissAnswersFailingPreconditionsFromTheEntry(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// An uncaught local request (outside every asset prefix, so neither catch |
| +// sees it) proxied to an app that sends the asset vocabulary on a 103: the |
| +// 103 reaches the client with its Link and without the vocabulary, on the |
| +// cacheable GET path and on the plain proxy path alike (final review F6). |
| +func TestUncaughtLocalInformationalVocabularyIsScrubbed(t *testing.T) { |
| + for _, method := range []string{http.MethodGet, http.MethodPost} { |
| + t.Run(method, func(t *testing.T) { |
| + s := newLAScene(t, vocabApp(laBody)) |
| + front := httptest.NewServer(s.e) |
| + t.Cleanup(front.Close) |
| + req, err := http.NewRequest(method, front.URL+"/index.html", nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req.Host = laHost |
| + var mu sync.Mutex |
| + var early []http.Header |
| + req = req.WithContext(httptrace.WithClientTrace(req.Context(), &httptrace.ClientTrace{ |
| + Got1xxResponse: func(code int, h textproto.MIMEHeader) error { |
| + mu.Lock() |
| + early = append(early, http.Header(h).Clone()) |
| + mu.Unlock() |
| + return nil |
| + }, |
| + })) |
| + resp, err := http.DefaultClient.Do(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer resp.Body.Close() |
| + if b, _ := io.ReadAll(resp.Body); string(b) != laBody { |
| + t.Fatalf("body = %q", b) |
| + } |
| + if got := resp.Header.Get(assetCacheHeader); got != "" { |
| + t.Fatalf("an uncaught response carried Carlos-Cache %q", got) |
| + } |
| + mu.Lock() |
| + defer mu.Unlock() |
| + if len(early) != 1 || early[0].Get("Link") == "" { |
| + t.Fatalf("1xx responses %v, want the app's 103 with its Link", early) |
| + } |
| + for _, name := range []string{assetAckHeader, assetExpiresHeader, assetCacheHeader, assetFillHeader} { |
| + if v := early[0].Values(name); len(v) > 0 { |
| + t.Errorf("the 103 carried %s %q", name, v) |
| + } |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/edge/assetcatch.go b/internal/edge/assetcatch.go| index 7074e04f4..945f6be0f 100644 |
| --- a/internal/edge/assetcatch.go |
| +++ b/internal/edge/assetcatch.go |
| @@ -8,6 +8,7 @@ import ( |
| "fmt" |
| "hash" |
| "net/http" |
| + "net/http/httputil" |
| "net/url" |
| "path" |
| "strconv" |
| @@ -1250,3 +1251,15 @@ func (s assetInformationalScrub) WriteHeader(code int) { |
| } |
| func (s assetInformationalScrub) Unwrap() http.ResponseWriter { return s.ResponseWriter } |
| + |
| +// assetScrubbedProxy is a tenant route's reverse proxy as Reload installs it: |
| +// every writer it is handed is wrapped in assetInformationalScrub, so an |
| +// app's 1xx loses the asset vocabulary on an uncaught local request as on a |
| +// backhaul. httputil.ReverseProxy flushes and hijacks through |
| +// http.ResponseController, which reaches the real writer through Unwrap, so |
| +// streaming and upgrades are unchanged. |
| +type assetScrubbedProxy struct{ proxy *httputil.ReverseProxy } |
| + |
| +func (p assetScrubbedProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| + p.proxy.ServeHTTP(assetInformationalScrub{w}, r) |
| +} |
diff --git a/internal/edge/edge.go b/internal/edge/edge.go| index 8675695e0..e986d4258 100644 |
| --- a/internal/edge/edge.go |
| +++ b/internal/edge/edge.go |
| @@ -907,6 +907,16 @@ func (e *Edge) Reload() error { |
| // A genManaged route is excluded too: its header comes from the |
| // generation that served the request (genRoundTripper, spec §7.2), |
| // and the registry's Version names only what is installed. |
| + // The asset cache's vocabulary never reaches a client from an app |
| + // (design §5.3). responseModifier strips it from a final response; |
| + // an informational one (103) is written from the proxy's trace |
| + // callback, past ModifyResponse, so every reverse proxy built above |
| + // writes through assetInformationalScrub, which strips it there. |
| + // Wrapping the handler covers each way the proxy is reached: the |
| + // ordinary path, the upgrade branch, the activator and a fill. |
| + if p, ok := proxy.(*httputil.ReverseProxy); ok { |
| + proxy = assetScrubbedProxy{p} |
| + } |
| if t.Version != "" && t.Kind != "static" && t.Kind != "status" && !genManaged { |
| proxy = versionHeader(t.Version, proxy) |
| } |