carlos / platform Public

edge: asset fix round 1: scrub every backhauled response; one backhaul admission

backhaulProxy's ModifyResponse now deletes the asset cache's vocabulary
(X-Carlos-Asset-Fill, -Fill-Ack, -Expires, Carlos-Cache) from the headers
and trailers of every backhauled response, caught or not, whatever the
home's version; a far edge's own fill keeps the acknowledgement and
expiry for fillFromHome, which verifies and then deletes them. 1xx
responses, which the proxy writes past ModifyResponse, are scrubbed at
the client boundary: assetInformationalScrub on every backhaul, and
assetResultWriter on every caught fallback.

backhaulAdmit is now the one place a backhaul slot is taken and both
refusals are written (429 for the fair share, 503 + Retry-After: 2 for
saturation), shared by backhaulTo and the far fill; the fill still holds
its slot for its exchange with the home and gives it back before any
re-forward.

Tests: the scrub on uncaught, unarmed, caught-fallback and unacknowledged
responses (1xx, headers, trailers); the local fallback's 1xx; the far
fill's 429 shed; and a buffered re-forward after a trailer veto billed
once, by the home, for the delivered bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 8ea4dbd9a1dcb302d92acd8a6d209a702de59fa3 parent 799fc12
3 files changed, +337 −68
  • internal/edge/asset_far_test.go +238 −0
  • internal/edge/assetcatch.go +47 −48
  • internal/edge/edge.go +52 −20

CI failed — run details

diff --git a/internal/edge/asset_far_test.go b/internal/edge/asset_far_test.go
index 8aaec5fff..9291f1914 100644
--- a/internal/edge/asset_far_test.go
+++ b/internal/edge/asset_far_test.go
@@ -8,6 +8,8 @@ import (
"net"
"net/http"
"net/http/httptest"
+ "net/http/httptrace"
+ "net/textproto"
"strconv"
"strings"
"sync"
@@ -877,3 +879,239 @@ func TestFarFillHoldsABackhaulSlot(t *testing.T) {
t.Fatal("the fill's backhaul slot was not given back")
}
}
+
+// ---- review round 1 -------------------------------------------------------
+
+// vocabApp answers like an app (or an old home) that sends the asset cache's
+// vocabulary everywhere it can: a 103 carrying it beside a Link, then final
+// headers and trailers (announced and not) carrying it, with an X-Kept
+// trailer that must still flow.
+func vocabApp(body string) http.HandlerFunc {
+ reserved := []string{assetAckHeader, assetExpiresHeader, assetCacheHeader, assetFillHeader}
+ return func(w http.ResponseWriter, r *http.Request) {
+ h := w.Header()
+ h.Set("Link", "</assets/app.js>; rel=preload")
+ for _, name := range reserved {
+ h.Set(name, "forged-1xx")
+ }
+ w.WriteHeader(http.StatusEarlyHints)
+ for _, name := range append([]string{"Link"}, reserved...) {
+ h.Del(name)
+ }
+ h.Set("Content-Type", "application/javascript")
+ h.Set("Cache-Control", "public, max-age=3600")
+ h.Set("Trailer", strings.Join(append([]string{"X-Kept"}, reserved[:2]...), ", "))
+ for _, name := range reserved {
+ h.Set(name, "forged")
+ }
+ io.WriteString(w, body)
+ w.(http.Flusher).Flush()
+ h.Set("X-Kept", "1")
+ h.Set(assetAckHeader, "forged-trailer")
+ h.Set(assetExpiresHeader, "4102444800")
+ h.Set(http.TrailerPrefix+assetCacheHeader, "forged-trailer")
+ h.Set(http.TrailerPrefix+assetFillHeader, "forged-trailer")
+ }
+}
+
+// Every backhauled response reaches its client without the asset
+// vocabulary, in a 1xx, a final header or a trailer, whether the far edge
+// caught the request or not: an older home box strips nothing.
+func TestBackhaulScrubsTheAssetVocabulary(t *testing.T) {
+ reserved := []string{assetAckHeader, assetExpiresHeader, assetCacheHeader, assetFillHeader}
+ for _, tc := range []struct {
+ name, path string
+ unarmed bool
+ noAck bool
+ cache string // the Carlos-Cache this edge itself answers, "" for none
+ fill bool // a fill, which forwards no 1xx at all (Task 5)
+ }{
+ {name: "uncaught path", path: "/index.html"},
+ {name: "unarmed edge", path: "/assets/app.js", unarmed: true},
+ {name: "caught non-canonical fallback", path: "/assets//app.js", cache: "bypass"},
+ {name: "caught unacknowledged fill", path: "/assets/app.js", noAck: true, cache: "bypass", fill: true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ s := newFarScene(t, vocabApp(laBody))
+ if tc.unarmed {
+ s.e.assets = nil
+ }
+ s.home.set(func(h *farHome) { h.ack = !tc.noAck })
+ front := httptest.NewServer(s.e)
+ t.Cleanup(front.Close)
+ req, err := http.NewRequest(http.MethodGet, front.URL+tc.path, 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)
+ }
+ mu.Lock()
+ defer mu.Unlock()
+ switch {
+ case tc.fill && len(early) != 0:
+ t.Fatalf("1xx responses %v, want none from a fill", early)
+ case !tc.fill && (len(early) != 1 || early[0].Get("Link") == ""):
+ t.Fatalf("1xx responses %v, want the home's 103 with its Link", early)
+ }
+ for _, name := range reserved {
+ for _, h := range early {
+ if v := h.Values(name); len(v) > 0 {
+ t.Errorf("the 103 carried %s %q", name, v)
+ }
+ }
+ if name == assetCacheHeader {
+ if got := resp.Header.Get(name); got != tc.cache {
+ t.Errorf("Carlos-Cache = %q, want %q", got, tc.cache)
+ }
+ } else if v := resp.Header.Values(name); len(v) > 0 {
+ t.Errorf("the response carried %s %q", name, v)
+ }
+ if _, ok := resp.Trailer[http.CanonicalHeaderKey(name)]; ok {
+ t.Errorf("the client received the %s trailer: %v", name, resp.Trailer)
+ }
+ for _, v := range resp.Header.Values("Trailer") {
+ if strings.Contains(strings.ToLower(v), strings.ToLower(name)) {
+ t.Errorf("the response announces the %s trailer: %q", name, v)
+ }
+ }
+ }
+ if got := resp.Trailer.Get("X-Kept"); got != "1" {
+ t.Errorf("X-Kept trailer = %q, want 1 (trailers %v)", got, resp.Trailer)
+ }
+ })
+ }
+}
+
+// The fair-share refusal of a far fill is the backhaul's own 429, with no
+// dial, and the flight is settled so nobody waits on it (D10).
+func TestFarFillShedByTheFairShareIs429(t *testing.T) {
+ s := newFarScene(t, assetOK(laBody))
+ s.e.rateMode = RateEnforce
+ req := s.req(http.MethodGet, "/assets/app.js")
+ key := s.e.backhaulClientKey(req)
+ if key == "" {
+ t.Fatal("precondition: the request must have a fair-share key")
+ }
+ for i := 0; i < 32; i++ {
+ release, ok, shed := s.e.backhaulAcquire("betty", key)
+ if !ok || shed {
+ t.Fatalf("holding slot %d: ok=%v shed=%v", i+1, ok, shed)
+ }
+ t.Cleanup(release)
+ }
+ rec := s.serve(req)
+ if rec.Code != http.StatusTooManyRequests || rec.Header().Get("Retry-After") != "1" || rec.Body.String() != rateLimitBody {
+ t.Fatalf("shed fill = %d Retry-After %q %q, want the backhaul's 429", rec.Code, rec.Header().Get("Retry-After"), rec.Body.String())
+ }
+ if n := s.rec.get().n; n != 0 {
+ t.Fatalf("the home saw %d requests, want none", n)
+ }
+ if n := flightWaitersOf(s.e, s.key("/assets/app.js").ID()); n != 0 || len(s.e.assets.flight.m) != 0 {
+ t.Fatalf("the refused fill left its flight open (%d waiters, %d flights)", n, len(s.e.assets.flight.m))
+ }
+ if v, _ := s.e.backhaulInflight.Load("betty"); v.(*atomic.Int64).Load() != 32 {
+ t.Fatalf("box count = %d, want the 32 held", v.(*atomic.Int64).Load())
+ }
+}
+
+// A buffered initiator whose acknowledged fill fails after the headers (a
+// Set-Cookie trailer vetoes it) is re-forwarded as a plain hop. That one
+// delivery is billed once, by the home that served it, for the bytes
+// delivered; the far edge bills nothing and the acknowledged fill nothing.
+func TestFarBufferedReforwardIsBilledOnce(t *testing.T) {
+ var home *laScene
+ homeMeter := NewUsageMeter()
+ s := newFarEdge(t, func(key []byte, m *homeMap) http.Handler {
+ home = newLAScene(t, func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/javascript")
+ w.Header().Set("Cache-Control", "public, max-age=3600")
+ w.Header().Set("Trailer", "Set-Cookie")
+ io.WriteString(w, laBody)
+ w.(http.Flusher).Flush()
+ w.Header().Set("Set-Cookie", "late=1")
+ })
+ hm := newHomeMap(m.s, "betty")
+ refreshHomeMap(t, hm)
+ home.e.homes.Store(hm)
+ home.e.EnableUsage(homeMeter)
+ return home.e
+ })
+ rec := s.get(t, "/assets/app.js", "Range", "bytes=0-6")
+ wantCache(t, rec, "bypass")
+ if rec.Code != 200 || rec.Body.String() != laBody {
+ t.Fatalf("re-forwarded = %d %q, want the app's whole answer", rec.Code, rec.Body.String())
+ }
+ if n := home.b.n.Load(); n != 3 {
+ t.Fatalf("the app saw %d requests, want 3 (the far fill, the home's own fill, its fallback)", n)
+ }
+ if st := s.store.Stats(); st.Entries != 0 {
+ t.Fatalf("the far edge stored a vetoed fill: %+v", st)
+ }
+ if req, _, ok := s.row(); ok && req != 0 {
+ t.Fatalf("the far edge billed %d request(s), want none: the home billed the delivery", req)
+ }
+ row := homeMeter.Drain()[laHost]
+ if row.Requests != 1 || row.BytesOut != int64(rec.Body.Len()) || row.HopRequests != 1 {
+ t.Fatalf("home row = %+v, want one hop of %d delivered bytes", row, rec.Body.Len())
+ }
+}
+
+// A caught request forwarded uncached on a box holding the route
+// (assetForward) gets the same 1xx scrub as a backhaul: the app's 103 keeps
+// its Link and loses the asset vocabulary.
+func TestLocalFallbackScrubsInformationalVocabulary(t *testing.T) {
+ s := newLAScene(t, vocabApp(laBody))
+ front := httptest.NewServer(s.e)
+ t.Cleanup(front.Close)
+ req, err := http.NewRequest(http.MethodGet, front.URL+"/assets//app.js", 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()
+ io.Copy(io.Discard, resp.Body)
+ if got := resp.Header.Get(assetCacheHeader); got != "bypass" {
+ t.Fatalf("Carlos-Cache = %q, want bypass", 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 e57c7f174..3c78d4746 100644
--- a/internal/edge/assetcatch.go
+++ b/internal/edge/assetcatch.go
@@ -444,6 +444,12 @@ type assetResultWriter struct {
}
func (a *assetResultWriter) WriteHeader(code int) {
+ if code < 200 {
+ // An informational response reaches the client past every response
+ // hook (the proxy writes it from its trace callback), so the asset
+ // vocabulary comes off it here.
+ stripAssetResponseHeaders(a.Header())
+ }
if code >= 200 && !a.wrote {
a.wrote = true
h := a.Header()
@@ -1068,18 +1074,9 @@ func (e *Edge) serveAssetFar(w http.ResponseWriter, r *http.Request, host string
forward()
return true
}
- releaseSlot, ok, shed := e.backhaulAcquire(box, e.backhaulClientKey(r))
- if shed {
- done(nil)
- writeRateLimited(w, time.Second)
- return true
- }
+ releaseSlot, ok := e.backhaulAdmit(w, r, eip, box)
if !ok {
done(nil)
- e.logThrottled("backhaul-saturated "+box,
- fmt.Sprintf("backhaul to %s (%s) is at its in-flight cap (%d) — answering 503 + Retry-After: 2", box, eip, backhaulMaxInflight.Load()))
- w.Header().Set("Retry-After", "2")
- http.Error(w, "temporarily busy", http.StatusServiceUnavailable)
return true
}
e.leadAssetFill(cw, r, nil, done, func(ctx context.Context, onHeader func(assetVerdict, http.Header)) (*assetcache.Entry, error) {
@@ -1132,7 +1129,7 @@ func (e *Edge) fillFromHome(ctx context.Context, w http.ResponseWriter, r *http.
}
send := func(w http.ResponseWriter, req *http.Request) {
req.Header.Set(assetFillHeader, assertion)
- backhaulProxy(host, eip, box, signHop(key, host, time.Now()), "", e.backhaulTransport(eip), e.logThrottled).ServeHTTP(w, req)
+ backhaulProxy(host, eip, box, signHop(key, host, time.Now()), "", true, e.backhaulTransport(eip), e.logThrottled).ServeHTTP(w, req)
}
return e.runAssetFill(ctx, w, r, k, host, judge, send, onHeader)
}
@@ -1153,56 +1150,58 @@ func assetAcknowledged(h http.Header, key []byte, assertion string) (expires int
}
// farForward is the far catch's uncached fallback: the ordinary backhaul,
-// answered Carlos-Cache: bypass. The backhaul proxy does not pass through
-// responseModifier, so the asset vocabulary is kept off the client's response
-// here, headers and trailers both. backhaulTo answers false only when the mesh
+// answered Carlos-Cache: bypass. backhaulTo answers false only when the mesh
// key went away after farAssetCatch read it; the client is then told to come
// back shortly rather than given an answer for a host this box does not
-// serve.
+// serve. The backhaul itself keeps the asset vocabulary off the response
+// (scrubBackhaulResponse, assetInformationalScrub).
func (e *Edge) farForward(w http.ResponseWriter, r *http.Request, host, eip, box string) {
- aw := &assetResultWriter{ResponseWriter: w, result: "bypass", onHeader: stripAssetFillVocabulary}
- if !e.backhaulTo(aw, r, host, eip, box) {
+ if !e.backhaulTo(&assetResultWriter{ResponseWriter: w, result: "bypass"}, r, host, eip, box) {
w.Header().Set("Retry-After", "2")
http.Error(w, "temporarily busy", http.StatusServiceUnavailable)
}
- stripAssetTrailerValues(w.Header())
}
-// stripAssetFillVocabulary deletes the fill's request and acknowledgement
-// headers from a response header map about to be written, and takes every
-// asset-vocabulary name out of its Trailer announcement, so a value sent
-// later under that name is not a trailer the client receives. Carlos-Cache,
-// set by this edge, stays.
+// stripAssetFillVocabulary deletes a far fill's assertion, acknowledgement
+// and expiry from the header map about to be written to the client, once
+// fillFromHome has read them (backhaulProxy keeps the acknowledgement and
+// expiry on a fill's response for exactly that). Carlos-Cache, set by this
+// edge, stays.
func stripAssetFillVocabulary(h http.Header) {
h.Del(assetFillHeader)
h.Del(assetAckHeader)
h.Del(assetExpiresHeader)
- vs := h.Values("Trailer")
- if len(vs) == 0 {
- return
- }
- var keep []string
- for _, v := range vs {
- for _, name := range strings.Split(v, ",") {
- if name = strings.TrimSpace(name); name != "" && !isAssetVocabulary(name) {
- keep = append(keep, name)
- }
- }
- }
- h.Del("Trailer")
- if len(keep) > 0 {
- h.Set("Trailer", strings.Join(keep, ", "))
- }
}
-// stripAssetTrailerValues deletes unannounced asset-vocabulary trailers
-// (http.TrailerPrefix keys) a proxy left in a handler's header map, before
-// the handler returns and the server sends them.
-func stripAssetTrailerValues(h http.Header) {
- for k := range h {
- if len(k) > len(http.TrailerPrefix) && strings.EqualFold(k[:len(http.TrailerPrefix)], http.TrailerPrefix) &&
- isAssetVocabulary(k[len(http.TrailerPrefix):]) {
- delete(h, k)
- }
+// scrubBackhaulResponse is the client boundary of every backhauled response
+// (backhaulProxy's ModifyResponse): the asset cache's vocabulary comes off
+// its headers and its trailers, announced or not, whatever version the home
+// box runs, so an app's own values never reach a client through a hop
+// (design §5.3). Carlos-Cache goes too: the far edge sets its own on what it
+// catches. A far edge's own fill (assetFill) keeps the acknowledgement and
+// expiry headers for fillFromHome, which verifies and then deletes them.
+func scrubBackhaulResponse(resp *http.Response, assetFill bool) {
+ resp.Header.Del(assetFillHeader)
+ resp.Header.Del(assetCacheHeader)
+ if !assetFill {
+ resp.Header.Del(assetAckHeader)
+ resp.Header.Del(assetExpiresHeader)
+ }
+ stripAssetTrailers(resp)
+}
+
+// assetInformationalScrub is the client boundary for a backhaul's 1xx
+// responses, which httputil.ReverseProxy writes from its trace callback,
+// past ModifyResponse: the asset vocabulary comes off each one. Final
+// responses pass untouched (scrubBackhaulResponse has done them). Unwrap
+// keeps flushing and an upgrade's hijack working through it.
+type assetInformationalScrub struct{ http.ResponseWriter }
+
+func (s assetInformationalScrub) WriteHeader(code int) {
+ if code < 200 {
+ stripAssetResponseHeaders(s.Header())
}
+ s.ResponseWriter.WriteHeader(code)
}
+
+func (s assetInformationalScrub) Unwrap() http.ResponseWriter { return s.ResponseWriter }
diff --git a/internal/edge/edge.go b/internal/edge/edge.go
index cbd4ae056..c1eb21a7b 100644
--- a/internal/edge/edge.go
+++ b/internal/edge/edge.go
@@ -3165,25 +3165,9 @@ func (e *Edge) backhaulTo(w http.ResponseWriter, r *http.Request, host, eip, box
return false
}
// Containment (the egress ruling, 2026-08-24), between the last guard and
- // the dial: a saturated home box is answered here, with no dial and no
- // bytes crossing a region. 503 + Retry-After: 2 is this package's
- // established "come back shortly" (staleHopRefusal, fleetProxy) and is
- // deliberately NOT the unknown-host answer — that is a 302 on a fallback
- // edge, which would lie to a legitimate client about where its app lives.
- // The log key is per home BOX, like "backhaul-error "+box below and for
- // the same bounded-key reason.
- releaseSlot, ok, shed := e.backhaulAcquire(box, e.backhaulClientKey(r))
- if shed {
- // The fair share, not saturation: this client holds its share of a
- // busy hop. The same 429 the home edge gives (writeRateLimited).
- writeRateLimited(w, time.Second)
- return true
- }
+ // the dial: backhaulAdmit answers a refused hop itself.
+ releaseSlot, ok := e.backhaulAdmit(w, r, eip, box)
if !ok {
- e.logThrottled("backhaul-saturated "+box,
- fmt.Sprintf("backhaul to %s (%s) is at its in-flight cap (%d) — answering 503 + Retry-After: 2", box, eip, backhaulMaxInflight.Load()))
- w.Header().Set("Retry-After", "2")
- http.Error(w, "temporarily busy", http.StatusServiceUnavailable)
return true
}
// Held until the hop's ServeHTTP returns, which for a stream or an
@@ -3200,10 +3184,46 @@ func (e *Edge) backhaulTo(w http.ResponseWriter, r *http.Request, host, eip, box
if _, ok := doorCallerFrom(r.Context()); ok {
doorAuth = signHopDoor(key, host, now)
}
- backhaulProxy(host, eip, box, auth, doorAuth, e.backhaulTransport(eip), e.logThrottled).ServeHTTP(w, r)
+ // The client boundary for informational responses: a 1xx from the home
+ // reaches w through the proxy's trace hook, past ModifyResponse, so the
+ // asset vocabulary comes off it here (assetInformationalScrub).
+ backhaulProxy(host, eip, box, auth, doorAuth, false, e.backhaulTransport(eip), e.logThrottled).ServeHTTP(assetInformationalScrub{w}, r)
return true
}
+// backhaulAdmit takes one backhaul slot toward box for r's client
+// (backhaulAcquire with backhaulClientKey), or answers the refusal on w and
+// reports false. It is the one place both refusals are written, for an
+// ordinary hop (backhaulTo) and for a far asset fill (serveAssetFar).
+//
+// A saturated home box is answered here, with no dial and no bytes crossing
+// a region. 503 + Retry-After: 2 is this package's established "come back
+// shortly" (staleHopRefusal, fleetProxy) and is deliberately NOT the
+// unknown-host answer — that is a 302 on a fallback edge, which would lie to
+// a legitimate client about where its app lives. The log key is per home
+// BOX, like "backhaul-error "+box in backhaulProxy and for the same
+// bounded-key reason. A fair-share refusal is the 429 the home edge gives.
+//
+// The caller releases the slot exactly once, when its exchange with the home
+// is over (backhaulAcquire).
+func (e *Edge) backhaulAdmit(w http.ResponseWriter, r *http.Request, eip, box string) (releaseSlot func(), ok bool) {
+ releaseSlot, ok, shed := e.backhaulAcquire(box, e.backhaulClientKey(r))
+ if shed {
+ // The fair share, not saturation: this client holds its share of a
+ // busy hop. The same 429 the home edge gives (writeRateLimited).
+ writeRateLimited(w, time.Second)
+ return nil, false
+ }
+ if !ok {
+ e.logThrottled("backhaul-saturated "+box,
+ fmt.Sprintf("backhaul to %s (%s) is at its in-flight cap (%d) — answering 503 + Retry-After: 2", box, eip, backhaulMaxInflight.Load()))
+ w.Header().Set("Retry-After", "2")
+ http.Error(w, "temporarily busy", http.StatusServiceUnavailable)
+ return nil, false
+ }
+ return releaseSlot, true
+}
+
// backhaulTransport is the cached outbound transport for one home box. The
// TRANSPORT is what is cached and the ReverseProxy above is what is rebuilt
// per request: a proxy value is two closures, while a transport owns the
@@ -3312,7 +3332,11 @@ func (e *Edge) backhaulTransport(eip string) *http.Transport {
// failed request for the whole outage. Keyed "backhaul-error "+box (per home
// box, not per host — a wildcard home behind one unreachable box would
// otherwise mint a fresh throttle bucket per invented hostname).
-func backhaulProxy(host, eip, box, auth, doorAuth string, tr http.RoundTripper, logThrottled func(key, msg string)) *httputil.ReverseProxy {
+//
+// assetFill is true only for a far edge's own asset fill (fillFromHome),
+// whose response is read by this edge before any client sees it; every
+// other hop passes false.
+func backhaulProxy(host, eip, box, auth, doorAuth string, assetFill bool, tr http.RoundTripper, logThrottled func(key, msg string)) *httputil.ReverseProxy {
return &httputil.ReverseProxy{
Rewrite: func(pr *httputil.ProxyRequest) {
setForwarded(pr)
@@ -3341,6 +3365,14 @@ func backhaulProxy(host, eip, box, auth, doorAuth string, tr http.RoundTripper,
scrubInboundPurgeHeader(pr)
},
Transport: tr,
+ // The asset cache's vocabulary never reaches a client from a home box,
+ // whatever the home's version (scrubBackhaulResponse). A far edge's
+ // own fill (assetFill) keeps the home's acknowledgement and expiry for
+ // fillFromHome to verify, which deletes them before the client.
+ ModifyResponse: func(resp *http.Response) error {
+ scrubBackhaulResponse(resp, assetFill)
+ return nil
+ },
ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) {
// 502, not the 503 + Retry-After that multiProxy and fleetProxy
// answer with: those two KNOW nobody is home (an empty live set, no