varnish-cache icon indicating copy to clipboard operation
varnish-cache copied to clipboard

VCL_PRIV access from a filter

Open nigoroll opened this issue 1 year ago • 4 comments

It is possible to parametrize filters through programmatic access to VRT_priv_task() from vmod functions and the filter code. But I see no way to access VCL_PRIVs from filter code. Can we add a way?

nigoroll avatar Sep 06 '22 13:09 nigoroll

Can't you grab it at init time? https://github.com/varnishcache/varnish-cache/pull/3772

dridi avatar Sep 07 '22 04:09 dridi

I would not see how, The VCL_PRIV can not be reached through the VRT_CTX, it is a static in the vcl object. One obvious possibility was to create an association (e.g. btree) between the vcl pointer (available as ctx->vcl) and the VCL_PRIV in the event function, and then use that to look up the vcl pointer later.

nigoroll avatar Sep 07 '22 09:09 nigoroll

In the VMOD function where you set up your filter, grab the PRIV_VCL and put it in a dynamic PRIV_TASK that can be queried from a VRT_CTX from the init callback.

dridi avatar Sep 07 '22 10:09 dridi

Yes, if that function exists. But the filter interface is designed that a simple

set resp.filters += " myfilter"

is sufficient. And there is no vmod function called for that.

nigoroll avatar Sep 07 '22 11:09 nigoroll