agentzh
February 26, 2010 11:04PM
On Sat, Feb 27, 2010 at 3:57 AM, Brian Pane <brianp@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
ngx_http_echo_location.c:

http://github.com/agentzh/echo-nginx-module/blob/master/src/ngx_http_echo_location.c

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.

Cheers,
-agentzh

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

unparsed_uri setting in ngx_http_subrequest?

Brian Pane 3130 February 26, 2010 03:00PM

Re: unparsed_uri setting in ngx_http_subrequest?

agentzh 1176 February 26, 2010 11:04PM

Re: unparsed_uri setting in ngx_http_subrequest?

Maxim Dounin 1467 February 27, 2010 06:18AM

Re: unparsed_uri setting in ngx_http_subrequest?

Brian Pane 1198 February 27, 2010 12:42PM

Re: unparsed_uri setting in ngx_http_subrequest?

Maxim Dounin 1058 February 27, 2010 01:18PM

Re: unparsed_uri setting in ngx_http_subrequest?

Brian Pane 1350 February 27, 2010 01:36PM

Re: unparsed_uri setting in ngx_http_subrequest?

Maxim Dounin 1129 February 27, 2010 01:58PM

Re: unparsed_uri setting in ngx_http_subrequest?

Brian Pane 1524 February 27, 2010 02:26PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 220
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready