3

During the recv subroutine I am currently changing my backend to another backend to handle the request, I need to declare a variable that will hold the value for the first/original backend that it was set to, so that when the request is restarted, I can then assign the backend back to this.

I can't just use the name for the backend and simply assign it back as I need it to be dynamic, storing it in a variable seems like the simplest solution but I can't seem to find any information on how this can be achieved through subroutines/ restarts.

If not possible are there any other solutions I could try to achieve this? Probably not possible from what I understand but even the ability to access an array of the backends defined and picking the first one would suffice, I just cant rely on naming the backend to assign it back.

C. Dodds
  • 325
  • 3
  • 12

1 Answers1

0

Unfortunately it isn't possible to declare a variable as a BACKEND type (which is what req.backend returns).

See this 'Fastly Fiddle' example that demonstrates you'll get a compiler error of:

Expected variable type, one of: BOOL, INTEGER, FLOAT, TIME, RTIME, IP or STRING

There also isn't any way to get a list of available backends via VCL either.

Additionally you would need to hardcode the backend value (i.e. you need to explicitly know what backends are defined from the VCL perspective) as trying to store a backend into a header or variable will convert it to a STRING type representation (such as 6kLtu7NicmMs0DtKsuite9--F_origin_0).

This means even if you were able to parse the actual F_origin_0 backend from the string you wouldn't be able to assign it as a value to req.backend as that expects the value to be of type BACKEND (and VCL doesn't provide a way, AFAIK, to convert a string into that type).

Integralist
  • 495
  • 3
  • 7