<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't change the parent's header,because the parent'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'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->connection->log->data;<br> r = ctx->request;<br><br> if (r != ctx->current_request) <br>
{<br> sr = ctx->current_request;<br> part = &sr->headers_out.headers.part;<br> h = part->elts;<br><br> /* set main status with subrequest */<br> if (r->headers_out.status != sr->headers_out.status) <br>
{<br> r->headers_out.status = sr->headers_out.status;<br><br> r->headers_out.status_line.data = NULL;<br> r->headers_out.status_line.len = 0;<br> }<br><br> /* clear out buffer */<br>
r->out = NULL;<br><br> for (i = 0; /* void */ ; i++) <br> {<br> if (i >= part->nelts) <br> {<br> if (part->next == NULL)<br> break;<br>
<br> part = part->next;<br> h = part->elts;<br> i = 0;<br> }<br><br> if (h->hash == 0)<br> continue;<br> <br> if (ngx_strncasecmp(h[i].key.data, (u_char *) "Set-Cookie", 10) == 0 ||<br>
ngx_strncasecmp(h[i].key.data, (u_char *) "Location", 8) == 0)<br> {<br> /* merge header: Set-Cookie*/<br> hh = ngx_list_push(&r->headers_out.headers);<br>
if (h == NULL) {<br> return NGX_HTTP_INTERNAL_SERVER_ERROR;<br> }<br><br> hh->hash = sr->header_hash;<br> hh->key = h[i].key;<br> hh->value = h[i].value;<br>
hh->lowcase_key = ngx_pnalloc(r->pool, h[i].key.len);<br> if (hh->lowcase_key == NULL) {<br> return NGX_HTTP_INTERNAL_SERVER_ERROR;<br> }<br><br> ngx_strlow(hh->lowcase_key, hh->key.data, hh->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'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'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>