Maxim Dounin
February 27, 2010 01:58PM
Hello!

On Sat, Feb 27, 2010 at 10:34:15AM -0800, Brian Pane wrote:

> On Sat, Feb 27, 2010 at 10:17 AM, Maxim Dounin <mdounin@mdounin.ru> wrote:
> > Hello!
> >
> > On Sat, Feb 27, 2010 at 09:39:56AM -0800, Brian Pane wrote:
> >
> >> I think I've found a separate bug in ngx_http_subrequest:
> >>
> >> ngx_http_core_module.c, line 2080 (in 0.8.33):
> >>     sr->headers_in = r->headers_in;
> >>
> >> This results in a bitwise copy of headers_in from the parent request
> >> to the subrequest.  Inside headers_in is a list:
> >> typedef struct {
> >>     ngx_list_t                        headers;
> >>     // ...
> >> } ngx_http_headers_in_t;
> >>
> >> When you do a bitwise copy of an ngx_list_t, you end up with a broken
> >> list.  Specifically, sr->headers_in->list->last in the subrequest
> >> points to the last node in the r->headers_in.list.part chain in the
> >> parent request.  It should instead point to the last node in the
> >> subrequest's sr->headers_in.list.part chain.
> >>
> >> Thus if any module attempts to add more headers to the subrequest's
> >> sr->headers_in, they actually will be added to the parent request's
> >> r->headers_in instead.
> >>
> >> I ran into this problem in a module that needs to add extra request
> >> headers to a proxied subrequest.
> >
> > It is expected that r->headers_in represent headers got from
> > client (i.e. inbound headers).  It is not expected to be modified
> > by anything but nginx core when it reads headers from client (and
> > some modules which sets special variables there, like
> > r->headers_in.user).
> >
> > To add headers to proxied [sub]request you have to use means
> > provided by proxy module, specifically proxy_set_header
> > configuration directive.
>
> I don't think proxy_set_header will work for what I'm doing,
> though, because I need to decide which headers to send
> to the upstream based on information that isn't known at

It is possible unless set of headers is infinite (i.e. set of
header names, not values). E.g.

proxy_set_header X-Something-1 $some_value_1;
proxy_set_header X-Something-2 $some_value_2;
proxy_set_header X-Something-3 $some_value_3;

Headers which values evaluate to empty string aren't sent.

Note well: proxy module itself uses this to provide ability to
pass X-Forwarded-For header with client's address added (see
$proxy_add_x_forwarded_for variable).

> configuration time. Is there a recommended programmatic
> way for another module to submit additional request headers
> to the proxy module on a per-request basis?

There is no one.

Maxim Dounin

_______________________________________________
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 3141 February 26, 2010 03:00PM

Re: unparsed_uri setting in ngx_http_subrequest?

agentzh 1180 February 26, 2010 11:04PM

Re: unparsed_uri setting in ngx_http_subrequest?

Maxim Dounin 1471 February 27, 2010 06:18AM

Re: unparsed_uri setting in ngx_http_subrequest?

Brian Pane 1204 February 27, 2010 12:42PM

Re: unparsed_uri setting in ngx_http_subrequest?

Maxim Dounin 1064 February 27, 2010 01:18PM

Re: unparsed_uri setting in ngx_http_subrequest?

Brian Pane 1355 February 27, 2010 01:36PM

Re: unparsed_uri setting in ngx_http_subrequest?

Maxim Dounin 1134 February 27, 2010 01:58PM

Re: unparsed_uri setting in ngx_http_subrequest?

Brian Pane 1530 February 27, 2010 02:26PM



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

Online Users

Guests: 316
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