Request-scoped variables

Brian Long brian at
Sat Feb 20 09:32:02 MSK 2010

Hi everyone,

I'm attempting to implement a module which generates a "request id (rid)"
variable. It's basically a uuid. The special requirement I have is that this
variable (call it $request_id) needs to be different per-request, but also
contain the same value if referenced multiple times in that request. For
example, I will use the variable in both a log_format directive as well as
a proxy_set_header directive. (Obviously the id is to log a request id that
can be used to correlated frontend requests to activity/exceptions on the
backends). So obviously I want to $request_id to be the same in log_format
and proxy_set_header, but at the same time different for every request.

I have the basic functionality of the variable working, but what I can't
figure out how to do is to keep the value the same during a single request.
Right now every time $request_is used, by get_handler is invoked and i
generated new uuid.

Is there some way of indicating the variable should be cached the request
scope, or is there somewhere I can store the variable in ngx_http_request_t*
for later retrieval?

I'll be releasing this project on github once I can complete this piece of
the functionality.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx-devel mailing list