From 07c4480e3ef7e3cb850aeffe4bc6c7d374952330 Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Wed, 1 Apr 2026 16:46:25 -0700 Subject: [PATCH] internal,fsthttp: add backend to HTTPCacheTransactionLookup() --- fsthttp/request.go | 2 ++ internal/abi/fastly/hostcalls_noguest.go | 4 ++++ internal/abi/fastly/httpcache_guest.go | 8 ++++++++ internal/abi/fastly/types.go | 3 +++ 4 files changed, 17 insertions(+) diff --git a/fsthttp/request.go b/fsthttp/request.go index 2c4908a..c59c13e 100644 --- a/fsthttp/request.go +++ b/fsthttp/request.go @@ -624,6 +624,8 @@ func (req *Request) sendWithGuestCache(ctx context.Context, backend string) (*Re req.CacheOptions.OverrideKey = "" } + options.Backend(backend) + // force the lookup to await in the host, retrieving any errors synchronously cacheHandle, err := fastly.HTTPCacheTransactionLookup(req.abi.req, &options) if err != nil { diff --git a/internal/abi/fastly/hostcalls_noguest.go b/internal/abi/fastly/hostcalls_noguest.go index 988984e..b0a6ba1 100644 --- a/internal/abi/fastly/hostcalls_noguest.go +++ b/internal/abi/fastly/hostcalls_noguest.go @@ -720,6 +720,10 @@ type HTTPCacheLookupOptions struct{} func (HTTPCacheLookupOptions) OverrideKey(key string) { } +func (HTTPCacheLookupOptions) Backend(backend string) { +} + + func HTTPCacheIsRequestCacheable(req *HTTPRequest) (bool, error) { return false, fmt.Errorf("not implemented") } diff --git a/internal/abi/fastly/httpcache_guest.go b/internal/abi/fastly/httpcache_guest.go index 71d7fc4..18162c1 100644 --- a/internal/abi/fastly/httpcache_guest.go +++ b/internal/abi/fastly/httpcache_guest.go @@ -21,6 +21,14 @@ func (o *HTTPCacheLookupOptions) OverrideKey(key string) { o.mask |= httpCacheLookupOptionsFlagOverrideKey } +func (o *HTTPCacheLookupOptions) Backend(backend string) { + b := []byte(backend) + buf := prim.NewReadBufferFromBytes(b) + o.opts.backendPtr = prim.ToPointer(buf.Char8Pointer()) + o.opts.backendLen = buf.Len() + o.mask |= httpCacheLookupOptionsFlagBackend +} + type HTTPCacheWriteOptions struct { mask httpCacheWriteOptionsMask opts httpCacheWriteOptions diff --git a/internal/abi/fastly/types.go b/internal/abi/fastly/types.go index e30d54b..06825c2 100644 --- a/internal/abi/fastly/types.go +++ b/internal/abi/fastly/types.go @@ -1824,6 +1824,8 @@ const ( type httpCacheLookupOptions struct { overrideKeyPtr prim.Pointer[prim.Char8] overrideKeyLen prim.Usize + backendPtr prim.Pointer[prim.Char8] + backendLen prim.Usize } type httpCacheLookupOptionsMask prim.U32 @@ -1831,6 +1833,7 @@ type httpCacheLookupOptionsMask prim.U32 const ( httpCacheLookupOptionsFlagReserved httpCacheLookupOptionsMask = 1 << 0 httpCacheLookupOptionsFlagOverrideKey httpCacheLookupOptionsMask = 1 << 1 + httpCacheLookupOptionsFlagBackend httpCacheLookupOptionsMask = 1 << 2 ) type (