# HG changeset patch # User Maxim Dounin # Date 1216087960 -14400 # Node ID ed63d0bd4d14ba0c3cff2b3e0be8f7da3f5db7aa # Parent ba5471a3c9883019fde64f95f37d82d143566b00 Correctly handle complex body filtering. - Postpone filter will maintain subrequests order, so don't worry about it. - Wait for last buffer before running subrequests, and don't touch anything after it. This allows us to reliably suppress whole original response. diff --git a/ngx_http_compose_filter_module.c b/ngx_http_compose_filter_module.c --- a/ngx_http_compose_filter_module.c +++ b/ngx_http_compose_filter_module.c @@ -220,7 +220,7 @@ ngx_http_compose_body_filter(ngx_http_re { ngx_str_t *uri, args; ngx_int_t rc; - ngx_uint_t i, flags; + ngx_uint_t i, flags, last; ngx_http_request_t *sr; ngx_http_compose_ctx_t *ctx; @@ -238,12 +238,9 @@ ngx_http_compose_body_filter(ngx_http_re if (ctx->done) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "compose body filter: done"); - /* XXX wrong: should skip data instead */ return ngx_http_next_body_filter(r, in); } - ctx->done = 1; - ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "compose body filter, doing work"); @@ -251,6 +248,22 @@ ngx_http_compose_body_filter(ngx_http_re * Ignore body that comes to us, replace it with subrequests. */ + last = 0; + + for ( ; in; in = in->next) { + in->buf->pos = in->buf->last; + if (in->buf->last_buf) { + last = 1; + in->buf->last_buf = 0; + } + } + + if (!last) { + return NGX_OK; + } + + ctx->done = 1; + uri = ctx->parts.elts; for (i = 0; i < ctx->parts.nelts; i++) { @@ -270,16 +283,6 @@ ngx_http_compose_body_filter(ngx_http_re } } - for ( ; in; in = in->next) { - in->buf->pos = in->buf->last; - in->buf->last_buf = 0; - } - - /* - * XXX: what to do if non-static data? probably we should use post - * subrequest hook instead - */ - return ngx_http_send_special(r, NGX_HTTP_LAST); }