]> granicus.if.org Git - apache/commitdiff
mod_lua: If the first yield() of a LuaOutputFilter returns a string, it should
authorEric Covener <covener@apache.org>
Mon, 2 Sep 2013 18:38:07 +0000 (18:38 +0000)
committerEric Covener <covener@apache.org>
Mon, 2 Sep 2013 18:38:07 +0000 (18:38 +0000)
be prefixed to the response as documented.

Also, don't put empty heap buckets in the brigade if a yield() is called with
no string.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1519492 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/lua/mod_lua.c

diff --git a/CHANGES b/CHANGES
index 573bb0f1df86e9be0257c0b1241a7d61df799ac8..1aba6899d45b34d47968802c0490c0ec00013578 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.0
 
+  *) mod_lua: If the first yield() of a LuaOutputFilter returns a string, it should
+     be prefixed to the response as documented. [Eric Covener]
+
   *) mod_lua: Remove ETAG, Content-Length, and Content-MD5 when a LuaOutputFilter
      is configured without mod_filter. [Eric Covener]
 
index bdf5b16dfb194463fe4edf16bc0b7029d42b335c..6e3390fbd2f346668c4f655821ec0c10e2a66fca 100644 (file)
@@ -416,8 +416,25 @@ static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade
             ap_remove_output_filter(f);
             return ap_pass_brigade(f->next,pbbIn);
         }
-        f->ctx = ctx;
-        ctx->tmpBucket = apr_brigade_create(r->pool, c->bucket_alloc);
+        else { 
+            /* We've got a willing lua filter, setup and check for a prefix */
+            size_t olen;
+            apr_bucket *pbktOut;
+            const char* output = lua_tolstring(ctx->L, 1, &olen);
+
+            f->ctx = ctx;
+            ctx->tmpBucket = apr_brigade_create(r->pool, c->bucket_alloc);
+
+            if (olen > 0) { 
+                pbktOut = apr_bucket_heap_create(output, olen, NULL, c->bucket_alloc);
+                APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktOut);
+                rv = ap_pass_brigade(f->next, ctx->tmpBucket);
+                apr_brigade_cleanup(ctx->tmpBucket);
+                if (rv != APR_SUCCESS) {
+                    return rv;
+                }
+            }
+        }
     }
     ctx = (lua_filter_ctx*) f->ctx;
     L = ctx->L;
@@ -442,13 +459,15 @@ static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade
             if (lua_resume(L, 0) == LUA_YIELD) {
                 size_t olen;
                 const char* output = lua_tolstring(L, 1, &olen);
-                pbktOut = apr_bucket_heap_create(output, olen, NULL,
-                                        c->bucket_alloc);
-                APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktOut);
-                rv = ap_pass_brigade(f->next, ctx->tmpBucket);
-                apr_brigade_cleanup(ctx->tmpBucket);
-                if (rv != APR_SUCCESS) {
-                    return rv;
+                if (olen > 0) { 
+                    pbktOut = apr_bucket_heap_create(output, olen, NULL,
+                                            c->bucket_alloc);
+                    APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktOut);
+                    rv = ap_pass_brigade(f->next, ctx->tmpBucket);
+                    apr_brigade_cleanup(ctx->tmpBucket);
+                    if (rv != APR_SUCCESS) {
+                        return rv;
+                    }
                 }
             }
             else {
@@ -470,9 +489,11 @@ static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade
                 apr_bucket *pbktOut;
                 size_t olen;
                 const char* output = lua_tolstring(L, 1, &olen);
-                pbktOut = apr_bucket_heap_create(output, olen, NULL,
-                                        c->bucket_alloc);
-                APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktOut);
+                if (olen > 0) { 
+                    pbktOut = apr_bucket_heap_create(output, olen, NULL,
+                            c->bucket_alloc);
+                    APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktOut);
+                }
             }
             pbktEOS = apr_bucket_eos_create(c->bucket_alloc);
             APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktEOS);