Welcome! Log In Create A New Profile

Advanced

Re: How to merge subrequest header.

Roast
November 25, 2010 05:44AM
Thanks agentzh.

You can register a post_subrequest callback function to your
> ngx_http_subrequest call and do subrequest header processing there.
>

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.

And I have fixed this problem, at the header filter function. Just like
following steps,maybe that's not a good way, agentzh pls give me some more
advanced suggestion.

static ngx_int_t
> ngx_http_social_header_filter(ngx_http_request_t *r)
> {
> ...... //some other works
>
> ctx = r->connection->log->data;
> r = ctx->request;
>
> if (r != ctx->current_request)
> {
> sr = ctx->current_request;
> part = &sr->headers_out.headers.part;
> h = part->elts;
>
> /* set main status with subrequest */
> if (r->headers_out.status != sr->headers_out.status)
> {
> r->headers_out.status = sr->headers_out.status;
>
> r->headers_out.status_line.data = NULL;
> r->headers_out.status_line.len = 0;
> }
>
> /* clear out buffer */
> r->out = NULL;
>
> for (i = 0; /* void */ ; i++)
> {
> if (i >= part->nelts)
> {
> if (part->next == NULL)
> break;
>
> part = part->next;
> h = part->elts;
> i = 0;
> }
>
> if (h->hash == 0)
> continue;
>
> if (ngx_strncasecmp(h[i].key.data, (u_char *) "Set-Cookie", 10)
> == 0 ||
> ngx_strncasecmp(h[i].key.data, (u_char *) "Location", 8) ==
> 0)
> {
> /* merge header: Set-Cookie*/
> hh = ngx_list_push(&r->headers_out.headers);
> if (h == NULL) {
> return NGX_HTTP_INTERNAL_SERVER_ERROR;
> }
>
> hh->hash = sr->header_hash;
> hh->key = h[i].key;
> hh->value = h[i].value;
> hh->lowcase_key = ngx_pnalloc(r->pool, h[i].key.len);
> if (hh->lowcase_key == NULL) {
> return NGX_HTTP_INTERNAL_SERVER_ERROR;
> }
>
> ngx_strlow(hh->lowcase_key, hh->key.data, hh->key.len);
> }
> }
> }
>
> ...... //some other works
>

>
return ngx_http_next_header_filter(r);
> }
>


You can check out the corresponding code in our ngx_echo or ngx_lua
> module. There's a live example for merging subrequest headers and body
> into the main request in ngx_lua (untested though, but *should* work):
>

That's two great module,but we need more work within our module.


--
The time you enjoy wasting is not wasted time!
_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

How to merge subrequest header.

Roast November 24, 2010 08:08AM

Re: How to merge subrequest header.

Roast November 24, 2010 08:02PM

Re: How to merge subrequest header.

agentzh November 25, 2010 05:24AM

Re: How to merge subrequest header.

agentzh November 25, 2010 05:34AM

Re: How to merge subrequest header.

Roast November 25, 2010 05:44AM

Re: How to merge subrequest header.

agentzh November 25, 2010 06:26AM

Re: How to merge subrequest header.

edo888 February 25, 2012 07:02PM

Re: How to merge subrequest header.

agentzh February 27, 2012 04:26AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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