Hi, I would like to understand how to import libraries into custom VCL files in Fastly?
It does not work using import or include. For example if I want to add std. I tried import std
or include std
or import "std"
in a custom VCL file, but it did not work. How do I do this?
Hi there,
You can include other VCL files:
But this doesn’t import the file as a module or object, it’s equivalent to simply pasting the content of the file at that point.
So what you want to tell me is that I need to include a complete library from somewhere else as a VCL file in Fastly to make this work? Are you serious? That is the only way?
The only ways to create encapsulated features in VCL that I know of are to use inline C, and to import vmods. These features are both unavailable to customers on the Fastly platform because if we let you write or import arbitrary C code it would create a way to escape the memory workspace allocated to your request, and also might unpredictably change the compute and memory requirements of your application. Our VCL services are tuned to operate at incredibly high throughput and do depend on well defined constraints that we can rely on.
So although the literal answer to your question above is yes, I suspect in reality what you want to achieve might not be possible within our VCL service constraints at all. But maybe there’s a way to do it with what we already provide in our VCL standard library - which is far more extensive than regular community Varnish. If you can describe your use case we can try and figure our the right solution.
That said, it’s also worth saying if you want to write code more freely and use third party libraries, take a look at our compute platform, where you can import anything you like, as long as it will compile successfully to webassembly we can run it:
Hi, thanks for your message.
So in our case, we are using the following modules in our Varnish Config, any suggestions on how to import these?
VMOD - Varnish Modules
Varnish Standard Module (vmod_std — Varnish version 3.0.7 documentation)
import std;
import directors;
import saintmode;
Variable support VMOD (GitHub - varnish/libvmod-var: Variable support VMOD)
import var;
VMOD - Varnish Modules
Varnish Module for Regular Expression Matching with Subexpression Capture (uplex-varnish / libvmod-re · GitLab)
import re;
Cookie VMOD (https://github.com/varnish/varnish-modules/blob/master/docs/vmod_cookie.rst)
import cookie;
I need to add those preferably in VCL Service, no Compute Platform
All of those features are included in Fastly VCL
Regex:
Custom variables:
Directors:
We don’t support saint mode but we recommend the use of healthchecks in conjunction with stale directives, which generally produce a better, more controllable outcome: