Hi @kieran
I’ve tried to reproduce this using Fastly Fiddle and it looks like it should work.
Let me take you through the reduced test case I created here:
https://fiddle.fastly.dev/fiddle/9d9c3107
So Fiddle uses https://http-me.glitch.me as its default backend and I’ve modified the incoming request to include parameters to mimic the behaviour we want (i.e. the backend to return a response that includes a x-goog-meta-surrogate-key
header.
I’ve also modified the path to have the backend return a standard surrogate-key
header just so I could see how Fastly behaves when handling the traditional use case.
In the vcl_fetch
I add the following code:
log beresp.http.x-goog-meta-surrogate-key;
log beresp.http.surrogate-key;
set beresp.http.Surrogate-Key = beresp.http.x-goog-meta-surrogate-key;
So I’m logging the values of both headers and I’m setting Surrogate-Key on the beresp
so that Fastly knows it has a surrogate key for the object it’s about to cache.
In vcl_fetch
you’ll see I also log the Surrogate-Key on the resp
object to see what its value is (because as documented, resp
is what’s sent back to the client and Fastly should be stripping Surrogate-Key from the client response):
log resp.http.surrogate-key;
OK, so first thing we notice is the response does send the headers we want it to send
The next thing we look at is the Fiddle data for the vcl_fetch
subroutine…
From this we see two useful things…
- We see the log output is what we expect
- We also see that Fastly is aware of the surrogate key (see the
skeys
) .
We can also see that skeys
was originally set to example2
(which came from the surrogate-key
header returned in the backend response) and is what we would expect .
The reason it’s no longer set to that but to example1
is of course because our code logic has overridden Fastly’s default behaviour by setting Surrogate-Key
explicitly to example1
(which comes from the Google header x-goog-meta-surrogate-key
returned in the backend response) and again, is what we would expect from this code logic .
NOTE: For anyone unaware the Surrogate-Key
header can contain multiple keys but they need to be space separated. So if we wanted to keep both key values then we’d append to the header instead of overwriting it completely. Something like…
set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key + " " + beresp.http.x-goog-meta-surrogate-key;
The next thing we look at is the Fiddle data for the vcl_deliver
subroutine and we see that Fastly has indeed stripped the Surrogate-Key
header from the resp
object so that header won’t be sent to the client. This is as per the Fastly documentation, and so the (null)
log output is what we would expect to see here
Lastly, we can confirm the removal of Surrogate-Key
from the response when we look at the actual response sent to the client…
Notice that the header is removed as expected, but also we can see the Google equivalent is still set (and we should probably remove that from either beresp
or more likely from resp
for security reasons).
But otherwise it looks like this should work fine
So my suggestion would be to try and remove any logic branches that might not be evaluating as you might expect them to be, or just log out their values (or log inside the conditional blocks to be sure it has been reached).
Hopefully this helps.
Let us know how you get on.