<span dir="ltr">Thanks agentzh</span>.<br><br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">You can register a post_subrequest callback function to your<br>


ngx_http_subrequest call and do subrequest header processing there.<br></blockquote><br>It seems post_subrequest callback function can&#39;t change the parent&#39;s header,because the parent&#39;s header filter has been process finished before the function call, and the output buf has created.<br>

 <br>And I have fixed this problem, at the header filter function. Just like following steps,maybe that&#39;s not a good way, <span dir="ltr">agentzh pls give me some more advanced suggestion</span>.<br><br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">

static ngx_int_t<br>ngx_http_social_header_filter(ngx_http_request_t *r)<br>{<br>    ...... //some other works<br><br>    ctx = r-&gt;connection-&gt;log-&gt;data;<br>    r = ctx-&gt;request;<br><br>    if (r !=  ctx-&gt;current_request) <br>

    {<br>        sr = ctx-&gt;current_request;<br>        part = &amp;sr-&gt;headers_out.headers.part;<br>        h = part-&gt;elts;<br><br>        /* set main status with subrequest */<br>        if (r-&gt;headers_out.status != sr-&gt;headers_out.status) <br>

        {<br>            r-&gt;headers_out.status = sr-&gt;headers_out.status;<br><br>            r-&gt;headers_out.status_line.data = NULL;<br>            r-&gt;headers_out.status_line.len = 0;<br>        }<br><br>        /* clear out buffer */<br>

        r-&gt;out = NULL;<br><br>        for (i = 0; /* void */ ; i++) <br>        {<br>            if (i &gt;= part-&gt;nelts) <br>            {<br>                if (part-&gt;next == NULL)<br>                    break;<br>

<br>                part = part-&gt;next;<br>                h = part-&gt;elts;<br>                i = 0;<br>            }<br><br>            if (h-&gt;hash == 0)<br>                continue;<br>            <br>            if (ngx_strncasecmp(h[i].key.data, (u_char *) &quot;Set-Cookie&quot;, 10) == 0 ||<br>

                ngx_strncasecmp(h[i].key.data, (u_char *) &quot;Location&quot;, 8) == 0)<br>            {<br>                /* merge header: Set-Cookie*/<br>                hh = ngx_list_push(&amp;r-&gt;headers_out.headers);<br>

                if (h == NULL) {<br>                    return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>                }<br><br>                hh-&gt;hash = sr-&gt;header_hash;<br>                hh-&gt;key = h[i].key;<br>                hh-&gt;value = h[i].value;<br>

                hh-&gt;lowcase_key = ngx_pnalloc(r-&gt;pool, h[i].key.len);<br>                if (hh-&gt;lowcase_key == NULL) {<br>                    return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>                }<br><br>                ngx_strlow(hh-&gt;lowcase_key, hh-&gt;key.data, hh-&gt;key.len);<br>

            }<br>        }<br>    }<br><br>    ...... //some other works<br></blockquote><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote"><div>

 </div></blockquote><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">    return ngx_http_next_header_filter(r);<br>}<br></blockquote><span dir="ltr"></span><br>

<br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">You can check out the corresponding code in our ngx_echo or ngx_lua<br>
module. There&#39;s a live example for merging subrequest headers and body<br>
into the main request in ngx_lua (untested though, but *should* work):<br></blockquote><div> </div>That&#39;s two great module,but we need more work within our module.<br><br clear="all"><br>-- <br>The time you enjoy wasting is not wasted time!<br>