# Module development question - Variables

**URL:** <https://www.ruby-forum.com/t/module-development-question-variables/236219>\
**Category:** NGINX\
**Created:** [August 15, 2013, 3:41pm UTC](https://www.ruby-forum.com/t/module-development-question-variables/236219 "2013-08-15T15:41:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [August 15, 2013, 3:41pm UTC](https://www.ruby-forum.com/t/module-development-question-variables/236219/1 "2013-08-15T15:41:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jandot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jandot](https://www.ruby-forum.com/u/jandot)\
**Post date:** [August 17, 2013, 5:32am UTC](https://www.ruby-forum.com/t/module-development-question-variables/236219/2 "2013-08-17T05:32:24Z")

</div>

Hello!

On Thu, Aug 15, 2013 at 03:40:59PM +0200, Jan A. 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.

> 1. 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 D.

> **[nginx: donation](http://nginx.org/en/donation.html)**
