proxy_pass takes Content-Length from another subrequest

Marat Dakota dakota at
Thu May 2 00:23:22 UTC 2013


My module makes a few subrequests with body (I populate sr->request_body
and set Content-Length in sr-headers_in).

These subrequests are landing to a locations that look like:

    location /backend {
        rewrite /backend(.+) $1 break;
        proxy_pass http://mybackend;

    location /backend2 {
        rewrite /backend2(.+) $1 break;
        proxy_pass http://mybackend2;

The problem is that proxy_pass takes Content-Length from the first
subrequest and uses it for the second subrequest. So, when the first
subrequest is longer than the second one, the second one never ends, and
when the first one is shorter, the second backend (mybackend2) receives
incomplete body.

I've spent quite a time tracing the problem and for the moment I've figured
out that Content-Length comes from these lines in ngx_http_proxy_module.c:

        while (*(uintptr_t *) e.ip) {
            code = *(ngx_http_script_code_pt *) e.ip;
            code((ngx_http_script_engine_t *) &e);

I haven't managed to go deeper at the moment.

So, question is — am I doing something wrong or is it a bug?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx-devel mailing list