Insert

Witold Filipczyk witekfl at gazeta.pl
Tue Oct 5 13:28:17 MSD 2010


Hi,
There is a body filter and:
in - first "chain"
b - current buf
u_char *p - position of '>'
cl - current "chain"
I want to insert the header after '>'.
ctx->header is u_char *
ctx->header_len is length

Code:
                cl2 = ngx_alloc_chain_link(r->pool);
                if (!cl2) {
                    return NGX_ERROR;
                }
                header = ngx_alloc_buf(r->pool);
                if (!header) {
                    return NGX_ERROR;
                }
                header->pos = ctx->header;
                header->last = ctx->header + ctx->header_len;
                header->memory = 1;
                cl2->buf = header;

                if (p == b->last - 1) {
                    cl2->next = cl->next;
                    cl->next = cl2;
                    ctx->state = NGX_LAYOUT_WAS_BODY;
                    return ngx_http_next_body_filter(r, in);
                }
                buf = ngx_alloc_buf(r->pool);
                if (!buf) {
                    return NGX_ERROR;
                }
                cl3 = ngx_alloc_chain_link(r->pool);
                if (!cl3) {
                    return NGX_ERROR;
                }
                buf->pos = p + 1;
                buf->last = b->last;
                b->last = p + 1;
                cl3->buf = buf;
                cl3->next = cl->next;
                cl2->next = cl3;
                cl->next = cl2;
                ctx->state = NGX_LAYOUT_WAS_BODY;
                return ngx_http_next_body_filter(r, in);

Is it correct?
I mean spliting b into two pieces.
Or something must be added to this code?



More information about the nginx-devel mailing list