On Thu, 4 Mar 2021 at 13:49, Adis Nezirovic <aneziro...@haproxy.com> wrote:

> On 3/4/21 1:39 PM, Mihaly Zachar wrote:
> > Dear Adis,
> >
> > Thank you very much for the prompt answer. It looks promising.
> > Yes, I do have the TXN object available.
> >
> > Currently I am checking the doc here:
> > http://cbonte.github.io/haproxy-dconv/2.2/configuration.html#8.2.4
> > <http://cbonte.github.io/haproxy-dconv/2.2/configuration.html#8.2.4>
> >
> > How can I use the sent back variable I don't see that in the variable
> > table :(
> >
> > Thank
>
>
> You have a few examples in our blog post:
> https://www.haproxy.com/blog/5-ways-to-extend-haproxy-with-lua/
>
> Basically, like using variables in HAProxy config, you need to set
> variable name using "scope.name" syntax, e.g. in the example scope is
> "req" (request), variable value is false.
>
> txn:set_var('req.blocked', false)
>
> Then, it should be able to log that variable by adding a block in
> log-format (no need to "capture" anything or similar):
>
> log-format "%{+Q}[var(txn.MyVar)]"
>
> A few blog posts about logging:
> https://www.haproxy.com/blog/introduction-to-haproxy-logging/
> https://www.haproxy.com/blog/haproxy-log-customization/
>
>
Hi Adis,

I was a bit too quick in the afternoon. I tried the thing from where I have
the TXN object available but it turned out that at that point I do not have
the result yet.
I also have a callback function registered with core.register_service(),
where I have the result I need to send back to the HAProxy layer.

It seems that this callback gets an AppletHTTP object. This object also has
a set_var() method.

If I do this:
applet:set_var('txn.myvar', 'myvar_value')

Then in the HAProxy layer I can reach the variable with %[var(txn.myvar)]
So it DOES work !
But Is this safe ? Did I do it well or I was just lucky ?

Thanks,
Misi

Reply via email to