I might have just figured out the answer to my own question. It looks like setting v->no_cacheable = 0 is what was required.<div><br></div><div>Here'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->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->len = 36;</div></div><div><div> v->valid = 1;</div></div><div><div> v->no_cacheable = 0;</div></div><div>
<div> v->not_found = 0;</div></div><div><div> v->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'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("request_id");</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, &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->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"><<a href="mailto:brian@dotspots.com">brian@dotspots.com</a>></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'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.</div>
<div><br></div><div>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.</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'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>