unparsed_uri setting in ngx_http_subrequest?
agentzh at gmail.com
Sat Feb 27 07:03:39 MSK 2010
On Sat, Feb 27, 2010 at 3:57 AM, Brian Pane <brianp at brianp.net> wrote:
> In ngx_http_subrequest, the newly initialized subrequest's
> unparsed_uri is set to the same value as the parent request's
> unparsed_uri. (I'm looking at 0.8.33.)
I believe it's a hole or even a bug. We can always get the original
unparsed_uri by reading r->main->unparsed_uri. It will result in
another weirdness when using the $request_uri variable in subrequests.
It's always the (unparsed) value of the main request.
There's a workaround though. After calling ngx_http_subrequest, you
can override the subrequest object's unparsed_uri field like this:
rc = ngx_http_subrequest(r, url, args, &sr, NULL, 0);
sr->unparsed_uri = generate_unparsed_uri(url);
We can do that because ngx_http_subrequest is an asynchronous call.
I'm doing lots of such adjustments in my ngx_echo module, for
instance, the ngx_http_echo_adjust_subrequest function in the
r->variables is also inherited by default. It's useful when
subrequests want to share the computed variable values with the parent
request, but it can also lead to some confusion when per-request
variables are desired.
More information about the nginx-devel