1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-08 15:02:10 +03:00

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
This commit is contained in:
Eric Covener
2013-09-02 18:38:07 +00:00
parent 918ccd0014
commit 227ffd6486
2 changed files with 36 additions and 12 deletions

View File

@@ -1,6 +1,9 @@
-*- coding: utf-8 -*- -*- coding: utf-8 -*-
Changes with Apache 2.5.0 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 *) mod_lua: Remove ETAG, Content-Length, and Content-MD5 when a LuaOutputFilter
is configured without mod_filter. [Eric Covener] is configured without mod_filter. [Eric Covener]

View 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); ap_remove_output_filter(f);
return ap_pass_brigade(f->next,pbbIn); return ap_pass_brigade(f->next,pbbIn);
} }
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; f->ctx = ctx;
ctx->tmpBucket = apr_brigade_create(r->pool, c->bucket_alloc); 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; ctx = (lua_filter_ctx*) f->ctx;
L = ctx->L; L = ctx->L;
@@ -442,6 +459,7 @@ static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade
if (lua_resume(L, 0) == LUA_YIELD) { if (lua_resume(L, 0) == LUA_YIELD) {
size_t olen; size_t olen;
const char* output = lua_tolstring(L, 1, &olen); const char* output = lua_tolstring(L, 1, &olen);
if (olen > 0) {
pbktOut = apr_bucket_heap_create(output, olen, NULL, pbktOut = apr_bucket_heap_create(output, olen, NULL,
c->bucket_alloc); c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktOut); APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktOut);
@@ -451,6 +469,7 @@ static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade
return rv; return rv;
} }
} }
}
else { else {
ctx->broken = 1; ctx->broken = 1;
ap_lua_release_state(L, ctx->spec, r); ap_lua_release_state(L, ctx->spec, r);
@@ -470,10 +489,12 @@ static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade
apr_bucket *pbktOut; apr_bucket *pbktOut;
size_t olen; size_t olen;
const char* output = lua_tolstring(L, 1, &olen); const char* output = lua_tolstring(L, 1, &olen);
if (olen > 0) {
pbktOut = apr_bucket_heap_create(output, olen, NULL, pbktOut = apr_bucket_heap_create(output, olen, NULL,
c->bucket_alloc); c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktOut); APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktOut);
} }
}
pbktEOS = apr_bucket_eos_create(c->bucket_alloc); pbktEOS = apr_bucket_eos_create(c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktEOS); APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktEOS);
ap_lua_release_state(L, ctx->spec, r); ap_lua_release_state(L, ctx->spec, r);