From: Eric Covener Date: Mon, 2 Sep 2013 18:38:07 +0000 (+0000) Subject: mod_lua: If the first yield() of a LuaOutputFilter returns a string, it should X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d28f923f208880680b30a3e512d27b13ff1cf4a;p=thirdparty%2Fapache%2Fhttpd.git mod_lua: If the first yield() of a LuaOutputFilter returns a string, it should 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 --- diff --git a/CHANGES b/CHANGES index 573bb0f1df8..1aba6899d45 100644 --- 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] diff --git a/modules/lua/mod_lua.c b/modules/lua/mod_lua.c index bdf5b16dfb1..6e3390fbd2f 100644 --- a/modules/lua/mod_lua.c +++ b/modules/lua/mod_lua.c @@ -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);