Welcome! Log In Create A New Profile

Advanced

Example body filter hangs when modified a little bit - request is not terminating.

January 10, 2018 08:05PM
I tried out this nginx example ngx_http_foo_body_filter body filter (here http://nginx.org/en/docs/dev/development_guide.html#http_body_buffers_reuse ) and got that to work just fine. It inserts a "foo" string before each incoming buffer.

I tried modifying a little bit so that it puts the foo string AFTER each incoming buffer chain in the list. The pages render correctly, but the request never terminates and the browser just sits there spinning. I don't know what I'm doing wrong. I'm pretty sure it is not module ordering because the original version works ok. I also set the content length to -1 in the header filter, etc.

In the debugger, the out linked chain looks right with no cycles or anything.

I appreciate any help you can give. Thank you.

Here is my version:

ngx_int_t
ngx_http_foo_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
ngx_int_t rc;
ngx_buf_t *b;
ngx_chain_t *cl, *tl, *out, **ll;
ngx_http_foo_filter_ctx_t *ctx;

ctx = ngx_http_get_module_ctx(r, ngx_http_foo_filter_module);
if (ctx == NULL) {
return ngx_http_next_body_filter(r, in);
}

/* create a new chain "out" from "in" with all the changes */

ll = &out;

for (cl = in; cl; cl = cl->next) {

/* append the next incoming buffer */

tl = ngx_alloc_chain_link(r->pool);
if (tl == NULL) {
return NGX_ERROR;
}

tl->buf = cl->buf;
*ll = tl;
ll = &tl->next;

/* append "foo" in a reused buffer if possible */

tl = ngx_chain_get_free_buf(r->pool, &ctx->free);
if (tl == NULL) {
return NGX_ERROR;
}

b = tl->buf;
b->tag = (ngx_buf_tag_t) &ngx_http_foo_filter_module;
b->memory = 1;
b->pos = (u_char *) "foo";
b->last = b->pos + 3;

*ll = tl;
ll = &tl->next;

}

*ll = NULL;

/* send the new chain */

rc = ngx_http_next_body_filter(r, out);

/* update "busy" and "free" chains for reuse */

ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &out,
(ngx_buf_tag_t) &ngx_http_foo_filter_module);

return rc;
}
Subject Author Posted

Example body filter hangs when modified a little bit - request is not terminating.

ptcell January 10, 2018 08:05PM

Re: Example body filter hangs when modified a little bit - request is not terminating.

tokers January 10, 2018 09:12PM

Re: Example body filter hangs when modified a little bit - request is not terminating.

ptcell January 10, 2018 11:20PM

Re: Example body filter hangs when modified a little bit - request is not terminating.

Roman Arutyunyan January 11, 2018 07:50AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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