Forum: NGINX Module development question - Variables

5897ccfea0a62691f880792a3b417bbe?d=identicon&s=25 Jan Algermissen (Guest)
on 2013-08-15 15:41
(Received via mailing list)
Hi,

been trying to understand variables for a couple of hours - but I jut
don't get it.

Can anyone explain,


1)  How and when the variable setter function is called?

2) Whether I should / can call it myelf to set the variable.

Use Case:

I write an access phase filter that extracts a bunch of information from
the Authorization header (think OAuth-like: clientId, user,  but maybe
also debug info about cryptography performance, token expiry, acess
ricghts -you get the idea).

I would like to store these per request values in a variable to use them
in the access log module to log them.

E.g.:

log_format gzip '$remote_addr - $remote_user $my_module_client,
$my_module_infoxy ...'

I think I understand what I have to do to create the variable (create in
preconfiguartin handler, provide setter function)

But how is the setter called and how  do I access the value to store in
the variable?

Should I make the value a static bucket in the module data that is
written per request and then copied to the variable in the variable
setter???

Existing modules only help a little, as they mostly set variables to
values that are part of the request struct anyway - which my values
aren't.

Jan
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2013-08-17 05:32
(Received via mailing list)
Hello!

On Thu, Aug 15, 2013 at 03:40:59PM +0200, Jan Algermissen wrote:

> Hi,
>
> been trying to understand variables for a couple of hours - but I jut don't get
it.
>
> Can anyone explain,
>
>
> 1)  How and when the variable setter function is called?

Something like this in a configuration:

    set  $variable  "foo";

will result in v->set_handler() being called during the "set"
directive evaluation.

> 2) Whether I should / can call it myelf to set the variable.

Usually no.

> E.g.:
> Should I make the value a static bucket in the module data that
> is written per request and then copied to the variable in the
> variable setter???
>
> Existing modules only help a little, as they mostly set
> variables to values that are part of the request struct anyway -
> which my values aren't.

In most cases, it's enough to store data in a module context and
provide a get_handler for a variable to access data via the module
context.

--
Maxim Dounin
http://nginx.org/en/donation.html
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.