changeset 2:ed63d0bd4d14

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 15 Jul 2008 06:12:40 +0400
parents ba5471a3c988
children 4d9427b61191
files ngx_http_compose_filter_module.c
diffstat 1 files changed, 17 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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);
 }