I might have just figured out the answer to my own question. It looks like setting v-&gt;no_cacheable = 0 is what was required.<div><br></div><div>Here&#39;s my get_handler:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">
<div><div>ngx_int_t ngx_x_rid_header_get_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) {</div></div><div><div>  u_char *p;     </div></div><div><div><br></div></div><div><div>  p = ngx_pnalloc(r-&gt;pool, 36);</div>
</div><div><div>  if (p == NULL) {</div></div><div><div>      return NGX_ERROR;</div></div><div><div>  }       </div></div><div><div>                </div></div><div><div>  uuid_t uuid;</div></div><div><div>  uuid_generate(uuid);       </div>
</div><div><div>  uuid_unparse_lower(uuid, (char*)p);</div></div><div><div><br></div></div><div><div>  v-&gt;len = 36;</div></div><div><div>  v-&gt;valid = 1;</div></div><div><div>  v-&gt;no_cacheable = 0;</div></div><div>
<div>  v-&gt;not_found = 0;</div></div><div><div>  v-&gt;data = p;</div></div><div><div><br></div></div><div><div>  return NGX_OK;</div></div><div><div>}          </div></div></blockquote><div><div><br></div><div>and here&#39;s where i add the variable:</div>
<div><br></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>static ngx_str_t  ngx_x_rid_header_variable_name = ngx_string(&quot;request_id&quot;);</div>
</div><div><div>static ngx_int_t ngx_x_rid_header_add_variables(ngx_conf_t *cf)</div></div><div><div>{</div></div><div><div>  ngx_http_variable_t* var = ngx_http_add_variable(cf, &amp;ngx_x_rid_header_variable_name, NGX_HTTP_VAR_NOHASH);</div>
</div><div><div>  if (var == NULL) {</div></div><div><div>      return NGX_ERROR;</div></div><div><div>  }</div></div><div><div>  var-&gt;get_handler = ngx_x_rid_header_get_variable;</div></div><div><div>  return NGX_OK;</div>
</div><div><div>}      </div></div></blockquote><div><div><br></div><div>Does this look like the correct setup? It does appear to be working now.</div><div><br></div><div>Thanks,</div><div>Brian                             </div>
<div><br></div><br><div class="gmail_quote">On Fri, Feb 19, 2010 at 11:32 PM, Brian Long <span dir="ltr">&lt;<a href="mailto:brian@dotspots.com">brian@dotspots.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi everyone,<div><br></div><div>I&#39;m attempting to implement a module which generates a &quot;request id (rid)&quot; variable. It&#39;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.</div>

<div><br></div><div>I have the basic functionality of the variable working, but what I can&#39;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.</div>

<div><br></div><div>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?</div><div><br></div><div>I&#39;ll be releasing this project on github once I can complete this piece of the functionality.</div>

<div><br></div><div>Thanks,</div><div>Brian</div>
</blockquote></div><br></div>