varnish / varnish-modules

Collection of Varnish Cache modules (vmods) by Varnish Software
Other
185 stars 86 forks source link

Feature request: var_module - ability to choose variables scope #111

Closed rsawer closed 6 years ago

rsawer commented 6 years ago

Hi, I'm trying to solve the problem of knowing the ESI includes status in the parent request by using the global variables of the var module. What I'm doing exactly is if I found an error in ESI response, then I'm creating a global variable called "error_". Then in the parent request I'm checking the existance of the "error_" var.

I'm worried that during the varnish lifetime, the memory will be full of error_* variables. I cannot use var.set/var.get because they're in PRIV_TASK scope, and I've found that there's a PRIV_TOP scope, which is designed for requests spanning through the parent and it's subrequests. I've tried simply changing that scope in vmod_var.vcc and recompile the modules, but unfortunatelly varnish crashes after calling the function with changed scope.

Would it be possible for you to implement a different scope variables?

daghf commented 6 years ago

By the time Varnish processes the includes, the top-level VCL processing is already over, so you won't be able to communicate back up the chain from a sub-request to the top-level request.

Getting PRIV_TOP would let you communicate state from a top-level request down to its children. That could certainly be a useful feature. I can't make any promises that it is something we will have time to do anytime soon, but if you're willing to take a stab I can tell you contributions are welcome.

rsawer commented 6 years ago

Thanks for the feedback, I'll be waiting for further development

nigoroll commented 6 years ago

@rsawer you might want to have a look at https://code.uplex.de/uplex-varnish/varnish-objvar/blob/master/src/vmod_topvar.rst from https://code.uplex.de/uplex-varnish/varnish-objvar

dridi commented 6 years ago

Closing in favor of @nigoroll's solution. Please reopen if his module does not suit you.