Accessing the body of the backend response in Varnish VCL

865 Views Asked by At

My Varnish VCL code needs to make a simple GET request into a backend system and decide if the requested resource is accessible or not. Unfortunately, the backend system always returns 200, and I must examine the actual body of the response to decide.

Is there a way to access the response body (which is under 1KB) in VCL and do a substring search on it?

I am trying to avoid implementing a proxy service just for this feature.

P.S. For now I have to stick with Varnish 2.1 (Fastly)

3

There are 3 best solutions below

0
On BEST ANSWER

Quick answer: no. Fastly's Varnish has diverged a lot from mainline, so you are basically stuck with what they provide and response body analysis isn't part of it.

Varnish 6.0 and 6.1 internals make that easier to build, but at the moment the vmod (xbody) you need is only available as a commercial product.

0
On

There is a way for some time now: You can use the .match_body() method of regex objects provided by vmod_re.

0
On

With varnish You probably should use external vmods for that

Opensource version: body-access in https://github.com/varnish/varnish-modules

Varnish Software/Entrprise : https://docs.varnish-software.com/varnish-enterprise/vmods/xbody/