Persistent data accross rewrite

Thibault Koechlin thibault.koechlin at
Thu Aug 18 16:45:49 UTC 2011

Hello List,

I'm currently working on a module that needs to parse every incoming
request, but only once. In the past, I was relying on r->internal to
decide if I need to parse the request or not, but my assumption was
wrong (I was naive and thinking I can always catch the request before it
goes "internal").

I figured out that if there is some rewrite (and probably in some other
cases), as my module is registered in the ACCESS phase, the r->internal
flag will be set when the request comes to the ACCESS phase (as the
rewrite phase is processed earlier and sets the r->internal flag). As
well, the module's CTX doesn't 'survive' to rewrite, so I cannot use
this neither.

I am looking for a way to keep "persistent" data across the whole
request life, some data that will not disappear with rewrites etc.
Actually, I just want to know if I already parsed the request or not, to
be sure to parse it only once. This data can be accessible only by my
module, that's not an issue.

I had a look at ngx_http_variable, but I'm afraid it's not adapted to my
needs, as it's persistent, and aimed at being accessed from config file,
while I just need a flag to say "this request has already been parsed,
don't parse it" or "this request has not been parsed, parse it, and set
the flag to said it has been parsed".

Except some (terribly wrong and dirty) tricks (like adding a field to
ngx_http_request_t, using global variables ...), I didn't find any way
to do so.

Can someone point me to something that might allow me to keep a 'flag'
for the whole request life ?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part
URL: <>

More information about the nginx-devel mailing list